Beruflich Dokumente
Kultur Dokumente
#include <stdio.h>
int t = 10;
main(){
int x = 0;
void funct1();
funct1();
printf("After first call \n");
funct1();
printf("After second call \n");
funct1();
printf("After third call \n");
}
void funct1()
{
static int y = 0;
int z = 10;
printf("value of y %d z %d",y,z);
y=y+10;
}
Yes. The const modifier means that this code cannot change the value of the
variable, but that does not mean that the value cannot be changed by means
outside this code. For instance, in the example in FAQ 8, the timer structure was
accessed through a volatile const pointer.
The function itself did not change the value of the timer, so it was declared const.
However, the value was changed by hardware on the computer, so it was
declared volatile. If a variable is both const and volatile, the two modifiers can
appear in either order.
Variable having block scope and without static specifier have automatic storage
duration.
Variables with block scope, and with static specifier have static scope. Global
variables (i.e, file scope) with or without the the static specifier also have static
scope.
Can include files be nested?
Yes. Include files can be nested any number of times. As long as you use
precautionary measures , you can avoid including the same file twice. In the past,
nesting header files was seen as bad programming practice, because it
complicates the dependency tracking function of the MAKE program and thus
slows down compilation. Many of today’s popular compilers make up for this
difficulty by implementing a concept called precompiled headers, in which all
headers and associated dependencies are stored in a precompiled state.
Many programmers like to create a custom header file that has #include
statements for every header needed for each module. This is perfectly acceptable
and can help avoid potential problems relating to #include files, such as
accidentally omitting an #include file in a module.
The stack is where all the functions’ local (auto) variables are created. The stack
also contains some information used to call and return from functions.
A stack trace is a list of which functions have been called, based on this
information. When you start using a debugger, one of the first things you should
learn is how to get a stack trace.
There used to be a C function that any programmer could use for allocating
memory off the stack. The memory was automatically deallocated when the
calling function returned. This was a dangerous function to call; it’s not available
anymore.
To set up pf to point to the strcmp() function, you want a declaration that looks
just like the strcmp() function’s declaration, but that has *pf rather than strcmp:
int (*pf)( const char *, const char * );
After you’ve gotten the declaration of pf, you can #include and assign the address
of strcmp() to pf: pf = strcmp;
The function main( ) invokes other functions within it.It is the first function to be
called when the program starts execution.
It is a user-defined function
Program execution ends when the closing brace of the function main( ) is
reached.
It has two arguments 1)argument count and 2) argument vector
(represents strings passed).
Any user-defined name can also be used as parameters for main( ) instead
of argc and argv
malloc(...) takes in only a single argument which is the memory required in bytes.
malloc(...) allocated bytes of memory and not blocks of memory like calloc(...).
2. malloc(...) allocates memory blocks and returns a void pointer to the allocated
space, or NULL if there is insufficient memory available.
The use of an enumeration constant (enum) has many advantages over using the
traditional symbolic constant style of #define. These advantages include a lower
maintenance requirement, improved program readability, and better debugging
capability.
1) The first advantage is that enumerated constants are generated automatically
by the compiler. Conversely, symbolic constants must be manually assigned
values by the programmer.
For instance, if you had an enumerated constant type for error codes that could
occur in your program, your enum definition could look something like this:
enum Error_Code
{
OUT_OF_MEMORY,
INSUFFICIENT_DISK_SPACE,
LOGIC_ERROR,
FILE_NOT_FOUND
};
In the preceding example, OUT_OF_MEMORY is automatically assigned the value
of 0 (zero) by the compiler because it appears first in the definition. The compiler
then continues to automatically assign numbers to the enumerated constants,
making INSUFFICIENT_DISK_SPACE equal to 1, LOGIC_ERROR equal to 2, and
FILE_NOT_FOUND equal to 3, so on.
If you were to approach the same example by using symbolic constants, your
code would look something like this:
#define OUT_OF_MEMORY 0
#define INSUFFICIENT_DISK_SPACE 1
#define LOGIC_ERROR 2
#define FILE_NOT_FOUND 3
values by the programmer. Each of the two methods arrives at the same result:
four constants assigned numeric values to represent error codes. Consider the
maintenance required, however, if you were to add two constants to represent
the error codes DRIVE_NOT_READY and CORRUPT_FILE. Using the enumeration
constant method, you simply would put these two constants anywhere in the
enum definition. The compiler would generate two unique values for these
constants. Using the symbolic constant method, you would have to manually
assign two new numbers to these constants. Additionally, you would want to
ensure that the numbers you assign to these constants are unique.
2) Another advantage of using the enumeration constant method is that your
programs are more readable and thus can be understood better by others who
might have to update your program later.
The difference between structure and union in c are: 1. union allocates the
memory equal to the maximum memory required by the member of the union
but structure allocates the memory equal to the total memory required by the
members. 2. In union, one block is used by all the member of the union but in
case of structure, each member have their own memory space
Read
more: http://wiki.answers.com/Q/What_are_the_differences_between_a_union_
and_a_structure_in_C#ixzz1WfqsWPsB
Read
more: http://wiki.answers.com/Q/What_are_the_differences_between_a_union_
and_a_structure_in_C#ixzz1Wfqut4Oo
what is pointer?
Pointer declaration:
int *ptr;
float *string;
Address operator:
ptr=#
The above code tells that the address where num is stores into the variable ptr.
The variable ptr has the value 21260,if num is stored in memory 21260 address
then
main()
{
int *ptr;
int sum;
sum=45;
ptr=∑
printf (“\n Sum is %d\n”, sum);
printf (“\n The sum pointer is %d”, ptr);
}
Pointer expressions & pointer arithmetic:
y=*p1**p2;
sum=sum+*p1;
z= 5* – *p2/p1;
*p2= *p2 + 10;
The following program illustrate the pointer expression and pointer arithmetic
1. Call by reference
2. Call by value.
Call by value:
We have seen that there will be a link established between the formal and actual
parameters when a function is invoked. As soon as temporary storage is created
where the value of actual parameters is stored. The formal parameters picks up
its value from storage area the mechanism of data transfer between formal and
actual parameters allows the actual parameters mechanism of data transfer is
referred as call by value. The corresponding formal parameter always represents
a local variable in the called function. The current value of the corresponding
actual parameter becomes the initial value of formal parameter. In the body of
the actual parameter, the value of formal parameter may be changed. In the body
of the subprogram, the value of formal parameter may be changed by assignment
or input statements. This will not change the value of the actual parameters.
fncn(p,q)
int p,q;
{
p=p+p;
q=q+q;
}
Call by Reference:
Pointer to arrays:
an array is actually very much similar like pointer. We can declare as int *a is an
address,because a[0] the arrays first element as a[0] and *a is also an address the
form of declaration is also equivalent. The difference is pointer can appear on the
left of the assignment operator and it is a is a variable that is lvalue. The array
name cannot appear as the left side of assignment operator and is constant.
We know the name of an array stands for address of its zeroth element the same
concept applies for names of arrays of structures. Suppose item is an array
variable of the struct type. Consider the following declaration:
struct products
{
char name[30];
int manufac;
float net;
item[2],*ptr;
this statement ptr as a pointer data objects of type struct products and declares
item as array of two elements, each type struct products.
Pointers on pointer
*ptr++, *p[],(ptr).member
Permalink Leave a Comment
Structure and union in C
February 16, 2008 at 9:08 pm · Filed under 15. Structure and union in C
What is a Structure?
structure definition:
general format:
struct tag_name
{
data type member1;
data type member2;
….
…
}
struct lib_books
{
char title[20];
char author[15];
int pages;
float price;
};
To holds the details of four fields namely title, author pages and price,the
keyword struct declares a structure. These are the members of the structures.
Each member may belong to same or different data type. The tag name can be
used to define the objects that have the tag names structure. The structure we
just declared is not a variable by itself but a template for the structure. We can
declare the structure variables using the tag name any where in the program. For
example the statement, struct lib_books book1,book2,book3; declares the
book1,book2,book3 as variables of type struct lib_books each declaration has four
elements of the structure lib_books. The complete structure declaration might
look like this
struct lib_books
{
char title[20];
char author[15];
int pages;
float price;
};struct lib_books, book1, book2, book3;
The node list is always keeps itself up-to-date. If an element is deleted or added,
in the node list or the XML document, the list is automatically updated.
The node list has a useful property called the length. The length property return
the number of node in a node list.
struct lib_books { char title[20]; char author[15]; int pages; float price; }; struct
lib_books, book1, book2, book3;
Union:
However the members that we compose a union all share the same storage area
within the computer’s memory where as each member within a structure is
assigned its own unique storage area. Thus unions are used to observe memory.
They are useful for the application involving multiple members. Where values
need not be assigned to all the members at any time. Unions like structure
contain members whose individual data types may differ from one another also.
Like structures union can be declared using the keyword union as follows:
union item
{
int m;
float p;
char c;
}
code;
The notation for accessing a union member that is nested inside a structure
remains the same as for the nested structure. In effect, a union creates a storage
location that can be used by one of its members at a time. When a different
number is assigned to a new value the new value super cedes the previous
member’s value. Unions may be used in all the places where a structure is
allowed.
What is a function?
Structure of a Function
There are two main parts of the functions. The function header and the function
body.
function body
}
Function Header
int sum(int x, int y)
It has three main parts
1. The function name i.e. sum
2. The parameters of the function enclosed in the paranthesis
3. Return value type of the function i.e. int
Function Body
What ever is written with in { } is the body of the function.
The following example shows the use of functions which prints factorial of a
number:
#iinclude
int I, factorial_number = 1;
int main(void)
{
int number = 0;
printf(“Enter a number\n”);
scanf(“%d”, &number);
calc_factorial (number);
return 0;
}
storage classes.
1. auto
2. extern
3. register
4. static.
auto
The auto keyword is used to place the specified variable into the stack area of
memory. In most variable declaration,this is usually implicit one, e.g. int i;
extern
The extern keyword is used to specify variable access the variable of the same
name from some other file. In modular programs,this is very useful for sharing
variables.
register
The register keyword gives suggest to the compiler to place the particular variable
in the fast register memory located directly on the CPU. Most compilers these
days (like gcc) are so smart that suggesting registers could actually make your
program more slower.
static
It is also used to declare the variables to be private to a certain file only when
declared with global variables. static can also be used with functions, making
those functions visible only to file itself.The static keyword is used for extending
the lifetime of a particular variable. The variable remains even after the function
call is long gone (the variable is placed in the alterable area of memory),if you
declare a static variable inside a function,. The static keyword can be overloaded.
what is a string?
A string is combination of characters.
Any set or sequence of characters defined within double quotation symbols
is a constant string.
In c it is required to do some meaningful operations on the strings
Initializing Strings
The initialization of a string must the following form which is simpler to the one
dimension array
strlen() function:
This function counts and returns the number of characters in a particular string.
The length always does not include a null character. The syntax of strlen() is as
follows:
n=strlen(string);
Where n is the integer variable which receives the value of length of the string.
The following program shows to find the length of the string using strlen()
function
/*writr a c program to find the length of the string using strlen() function*/
#include < stdio.h >
include < string.h >
void main()
{
char name[100];
int length;
printf(”Enter the string”);
gets(name);
length=strlen(name);
printf(”\nNumber of characters in the string is=%d”,length);
}
strcat() function:
when you combine two strings, you add the characters of one string to the end of
the other string. This process is called as concatenation. The strcat() function is
used to joins 2 strings together. It takes the following form:
strcat(string1,string2)
string1 & string2 are the character arrays. When the function strcat is executed
string2 is appended to the string1. the string at string2 always remains
unchanged.
strcmp function:
In c,you cannot directly compare the value of 2 strings in a condition like
if(string1==string2) Most libraries however contain the function called
strcmp(),which returns a zero if 2 strings are equal, or a non zero number if the
strings are not the same. The syntax of strcmp() is given below:
Strcmp(string1,string2)
strcmpi() function
This function is same as strcmp() which compares 2 strings but not case sensitive.
Strcmp(string1,string2)
strcpy() function:
To assign the characters to a string,C does not allow you directly as in the
statement name=Robert; Instead use the strcpy() function found in most
compilers the syntax of the function is illustrated below.
strcpy(string1,string2);
strlwr () function:
This function converts all characters in a string from uppercase to lowercase
The syntax of the function strlwr is illustrated below
strlwr(string);
strrev() function:
This function reverses the characters in a particular string. The syntax of the
function strrev is illustrated below
strrev(string);
· It is wasteful when dealing with array type structures to allocate so much space
when it is declared
Five ANSI Standartd Function Used in Dynamic Memory Allocation
ANSI C provides five standard functions that will help you allocate memory on the
heap which are as follows:
1. sizeof()
2. malloc()
3. calloc()
4. realloc()
5. free()
The following table describe the five different standard functions that helps you
allocate memory dynamically
Functio
Task
n
The sizeof() function returns the memory size of the requested
Sizeof
variable
Allocates memory requests size of bytes and returns a pointer to the
Malloc
Ist byte of allocated space
Allocates space for an array of elements initializes them to zero and
Calloc
returns a pointer to the memory
Free Frees previously allocated space
Realloc Modifies the size of previously allocated space.
sizeof()
The sizeof() function returns the memory size of requested variable. This call
should be used in the conjunction with the calloc() function call, so that only the
necessary memory is allocated, rather than a fixed size. Consider the following,
struct date {
int hour, minute, second;
};
int x;
malloc()
A block mf memory may be allocated using the function called malloc. The malloc
function reserves a block of memory of specified size and return a pointer of type
void. This means that we can assign it to any type of the pointer. It takes the
following form:
ptr=(cast-type*)malloc(byte-size);
ptr is a pointer of type cast-type the malloc returns a pointer (of cast type) to an
area of memory with the size byte-size. The following is the example of using
malloc function
x=(int*)malloc(100*sizeof(int));
calloc()
Calloc is another memory allocation function that is normally used to request the
multiple blocks of storage each of same size and then sets all bytes to zero. The
general form of calloc is:
ptr=(cast-type*) calloc(n,elem-size);
The above statement allocates contiguous space for n blocks each size of the
elements size bytes. All bytes are initialized to zero and a pointer to the first byte
of allocated region is returned. If there is not enough space a null pointer is also
returned.
realloc()
The memory allocated by using calloc or malloc might be insufficient or excess
sometimes in both the situations we can change the memory size already
allocated with the help of the function called realloc. This process is called the
reallocation of memory. The general statement of reallocation of memory is :
ptr=realloc(ptr,newsize);
free()
Compile time storage of a variable is allocated and released by the system in
accordance with its storage class. With the dynamic runtime allocation, it is our
responsibility to release the space when it is not required at all.When the storage
is limited,the release of storage space becomes important . When we no longer
need the data we stored in a block of memory and we do not intend to use that
block for the storing any other information, Using the free function,we may
release that block of memory for future use.
free(ptr);
ptr is a pointer that has been created by using calloc or malloc.
The following program illustrate the reallocation of memory using realloc() and
malloc()
/*Example program for reallocation*/
What is an array?
* Arrays are collection of similar items (i.e. ints, floats, chars) whose memory is
allocated in a contiguous block of memory.
Declaration of arrays
Arrays must be declared before they are used like any other variable. The general
form of declaration is:
type variable-name[SIZE];
The type specify the type of the elements that will be contained in the array, such
as int,float or char and the size indicate the maximum number of elements that
can be stored inside the array.
The following example illustrate the use of array:
float height[50];
Declares the height to be an array containing the 50 real elements. Any subscripts
0 to 49 are all valid. In C the array elements index or subscript begins with the
number zero. So height [0] refers to first element of the array. (For this reason, it
is easier to think of it as referring to element number zero, rather than as
referring to first element). The declaration int values[10]; would reserve the
enough space for an array called values that could hold up to 10 integers. Refer to
below given picture to conceptualize the reserved storage space.
values[0]
values[1]
values[2]
values[3]
values[4]
values[5]
values[6]
values[7]
values[8]
values[9]
Initialization of arrays:
We can initialize the elements in an array in the same way as the ordinary
variables when they are declared. The general form of initialization off arrays is:
data_type array_name[row_size][column_size];
int m[10][20];
The following program illustrate addition two matrices & store the results in the
3rd matrix
/* example program to add two matrices & store the results in the 3rd matrix */
#include< stdio.h >
#include< conio.h >
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q;
clrscr();
printf(“enter the order of the matrix\n”);
scanf(“%d%d”,&p,&q);
if(m==p && n==q)
{
printf(“matrix can be added\n”);
printf(“enter the elements of the matrix a”);
for(i=0;i < m;i++)
for(j=0;j
scanf(%d,&a[i][j]);
printf(“enter the elements of the matrix b”);
for(i=0;i < p;i++)
for(j=0;j
scanf(%d,&b[i][j]);
printf(“the sum of the matrix a and b is”);
for(i=0;i
for(j=0;j
c[i][j]=a[i][j]+b[i][j];
for(i=0;i < m;i++)
{ for(j=0;j
printf(%d\t,&a[i][j]);
printf(\n);
}
}
The C Preprocessor is a separate step in the compilation process, but not part of
the compiler.
* C Preprocessor is just a text substitution tool and we’ll refer to the C
Preprocessor as the CPP
The C preprocessor.
All preprocessor lines always begin with #. This listing is from Weiss pg. 104.
The unconditional directives are as follows:
o #define – Define a preprocessor macro
o #include – Insert a particular header from another file
o #undef – Undefine a preprocessor macro
#include
#include “mystring.h”
The above code tells the CPP to get stdio.h from System Libraries and add the text
to this file. The next line tells CPP to get mystring.h from the local directory and
then add the text to the file.
#undef MEANING_OF_LIFE
#define MEANING_OF_LIFE 42
The above code tells the CPP to undefine MEANING_OF_LIFE and define it for 42.
#ifndef IROCK
#define IROCK “You wish!”
#endif
The above code tells the CPP to define IROCK only if IROCK isn’t defined already.
#ifdef DEBUG
/* Your debugging statements here */
#endif
Thed above code tells the CPP to do the following statements if DEBUG is
defined.If you pass the -DDEBUG flag to gcc,this is useful .
Permalink Leave a Comment
The C operators fall into the following categories:
Precedence of C Operators
Category Operator Associativity
Postfix () [] -> . ++ – - Left to right
Unary + – ! ~ ++ – - (type) * & sizeof Right to left
Multiplicative */% Left to right
Additive +– Left to right
Shift << >> Left to right
Relational < <= > >= Left to right
Equality == != Left to right
Bitwise AND & Left to right
Bitwise XOR ^ Left to right
Bitwise OR | Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= %= >>= <<= &= ^= |= Right to left
Comma , Left to right
getchar
getchar always returns the next character of keyboard input as an int. The EOF
(end of file) is returned,if there is an error . It is usual to compare this value
against EOF before using it. So error conditions will not be handled correctly,if the
return value is stored in a char, it will never be equal to EOF.
The following program is used to count the number of characters read until an
EOF is encountered. EOF can be generated by typing Control – d.
#include
main()
{ int ch, i = 0;
putchar
putchar puts its character argument on the standard output (usually the screen).
The following example program converts any typed input into capital letters.It
applies the function toupper from the character conversion library ctype.h to
each character in turn to do this.
main()
{ int ch;
while((ch = getchar()) != EOF)
putchar(toupper(ch));
}
printf
This offers more structured output than the putchar. Its arguments are, in order;
a control string, which controls what get printed, followed by a list of values to be
substituted for entries in the control string. The prototype for the printf() is:
%d Decimal Integer
%c Single Character
%s Character String
With the use of the formatting line,you can format the output.You can change
how the particular variable is placed in output,by modifying the conversion
specification, . For example
printf(“%10.4d”, x);
The . allows for the precision.To floats as well,this can be applied.The number 5 is
on the tenth spacing as the number 10 puts 0005 over 10 spaces. You can also
add – and + right after % to make the number explicitly output as +0005. Note
that the value of x does not actually change. In other words,you will not get
output using %-10.4d will not output -0005. %e is useful for outputting floats
using the scientific notation. %le for doubles and %Le for the long doubles.
To grab things from input,scanf() is used. Beware though, scanf isn’t greatest
function that C has to offer. Some people brush off the scanf as a broken function
that shouldn’t be used often. The prototype for scanf is:
Last example will create a rectangle with rounded corner:
for ( ; ; ) {
printf(“Enter an integer bub: “);
if (( args = scanf(“%d”, &x)) == 0) {
printf(“Error: not an integer\n”);
continue;
} else {
if (args == 1)
printf(“Read in %d\n”, x);
else
break;
}
}
When should the volatile modifier be used ?
Most computers have a set of registers that can be accessed faster than the
computer’s main memory. A good compiler will perform a kind of optimization
called redundant load and store removal. The compiler looks for places in the
code where it can either remove an instruction to load data from memory
because the value is already in a register, or remove an instruction to store data
to memory because the value can stay in a register until it is changed again
anyway.
If a variable is a pointer to something other than normal memory, such as
memory-mapped ports on a peripheral, redundant load and store optimizations
might be detrimental. For instance, here’s a piece of code that might be used to
time some operation:
In this code, the variable t-> value is actually a hardware counter that is being
incremented as time passes. The function adds the value of a to x 1000 times, and
it returns the amount the timer was incremented by while the 1000 additions
were being performed. Without the volatile modifier, a clever optimizer might
assume that the value of t does not change during the execution of the function,
because there is no statement that explicitly changes it. In that case, there’s no
need to read it from memory a second time and subtract it, because the answer
will always be 0.
The compiler might therefore optimize the function by making it always return 0.
If a variable points to data in shared memory, you also don’t want the compiler to
perform redundant load and store optimizations. Shared memory is normally
used to enable two programs to communicate with each other by having one
program store data in the shared portion of memory and the other program read
the same portion of memory. If the compiler optimizes away a load or store of
shared memory, communication between the two programs will be affected.
#includemain() {
printf(”Hello, world!\n”);
return 0;
}
Seems like trying to figure out all this is just way too confusing.
Then the return 0 statement. Seems like we are trying to give something
back, and it gives the result as an integer. Maybe if we modified our main
function definition: int main() ,now we are saying that our main function will
be returning an integer!So,you should always explicitly declare the return
type on the function.
Let us add #include to our includes. Let’s change our original return
statement to return EXIT_SUCCESS;. Now it makes sense!
printf always returns an int. The main pages say that printf returns the
number of characters printed.It is good programming practice to check for
return values. It will not only make your program more readable, but at the
end it will make your programs less error prone. But we don’t really need it in
this particular case.So we cast the function’s return to (void). fprintf,exit and
fflush are the only functions where you should do this.
What about the documentation? We should probably document some of
our code so that other people can understand what we are doing. Comments
in the C89 standard are noted by this: /* */. The comment always begins with
/* and ends with */.
int main() {
(void)printf(”Hello, world!\n”);
return EXIT_SUCCESS;
}
Note:The KEY POINT of this whole introduction is to show you the fundamental
difference between understandability and correctness. If you lose
understandability in an attempt to gain correctness, you will lose at the end.
Always place the understandability as a priority ABOVE correctness. If a program
is more understandable in the end,the chances it can be fixed correctly will be
much higher. It is recommend that you should always document your program.
You stand less of a chance of screwing up your program later,if you try to make
your program itself more understandable.
The advantages of C
In other words,for writing anything from small programs for personal amusement
to complex industrial applications,C is one of a large number of high-level
languages designed for general-purpose programming.
C has many advantages:
Compilation
There are many C compilers are present around. The cc is being the default Sun
compiler. The GNU C compiler gcc is popular and also available for many
platforms. PC users may also be familiar with Borland bcc compiler.
There are also C++ compilers which are usually denoted by CC (note upper case
CC.For example Sun provides GNU and CCGCC. The GNU compiler is also denoted
by the command g++
Other C/C++ compilers also exist. All the above compilers operate in essentially
the share many common command line options and same manner. However,
thebest source of each compiler is through online manual pages of your
system: e.g.man cc.
In the basic discussions of compiler operation,for the sake of compactness,we will
simply refer to the cc compiler — other compilers can simply be substituted in
place of cc until and unless otherwise stated.
Your program simply invoke the command cc to Compile . The command must be
followed by the name of the (C) program you wish to compile it.
The compilation command is:
cc program.c
where program.c is name of the file.
If there are obvious errors in your program (such as mistypings, misspelling one of
the key words or omitting a semi-colon), the compiler will detect it and report
them.
It may possible that the compiler cannot detect logical errors.
If the compiler option -o is used : the file listed after the -oor when the compiler
has successfully digested your program, the compiled version, or executable, is
left in a file called a.out
It is convenient to use a -o and filename in the compilation as in
cc -o program program.c
which puts the compiled program into the file program ( any file you name
following the “-o” argument) instead of putting it in the file a.out .
Characteristics of C
We briefly list some of C’s characteristics that have lead to its popularity as a
programming language and define the language. Naturally we will be studying
many of these aspects throughout our tutorial.
C has now become a widely used professional language for various reasons.
The main drawback of c is that it has poor error detection which can make it off
putting to the beginner. However diligence in this matter can pay off handsomely
since having learned the rules of the C we can break them. Not all languages allow
this. This if done carefully and properly leads to the power of C programming.
C Program Structure
A C program basically has the following form:
Preprocessor Commands
Function prototypes — declare function types and variables passed to
function.
Type definitions
Variables
Functions