Sei sulla pagina 1di 8

MSc-I

Roll No.12

Overview Of C Programming
Introduction C was invented to write an operating system called UNIX. C is a successor of B language, which was introduced around 1970. The language was formalized in 1988 by the American National Standard Institute. (ANSI). The UNIX OS was totally written in C by 1973. Today, C is the most widely used and popular System Programming Language. Most of the state-of-the-art softwares have been implemented using C. Today's most ][popular Linux OS and RBDMS MySQL have been written in C.

Compiler vs Interpretor In its simplest form, an interpreter reads the source code of your program one line at a time, performing the specific instructions contained in that line. In languages such as Java, a program's source code is first converted into an intermediary form that is then interpreted. In either case, a run-time interpreter is still required to be present to execute the program. A compiler reads the entire program and converts it into object code, which is a translation of the program's source code into a form that the computer can execute directly. Object code is also referred to as binary code or machine code. Once the program is compiled, a line of source code is no longer meaningful in the execution of your program. Keywords The following list shows the reserved words in C. These reserved words may not be used as constant or variable or any other identifier names. auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while

Niranjana.S.Karandikar

Page 1

MSc-I

Roll No.12

Data Types A set of values that a variable can store along with a set of operations that can be performed on that variable. There are only a few basic data types in C: char a single byte, capable of holding one character in the local character set int an integer, typically reflecting the natural size of integers on the host machine float single-precision floating point double double-precision floating point In addition, there are a number of qualifiers that can be applied to these basic types. short and long apply to integers.The word int can be omitted in such declarations. The intent is that short and long should provide different lengths of integers where practical; int will normally be the natural size for a particular machine. short is often 16 bits long, and int either 16 or 32 bits. Each compiler is free to choose appropriate sizes for its own hardware, subject only to the the restriction that shorts and ints are at least 16 bits, longs are at least 32 bits, and short is no longer than int, which is no longer than long. The qualifier signed or unsigned may be applied to char or any integer. unsigned numbers are always positive or zero, and obey the laws of arithmetic modulo 2n, where n is the number of bits in the type. So, for instance, if chars are 8 bits, unsigned char variables have values between 0 and 255,while signed chars have values between -128 and 127 (in a two's complement machine.) Whether plain chars are signed or unsigned is machine-dependent, but printable characters are always positive. The type long double specifies extended-precision floating point. As with integers, the sizes of floating-point objects are implementation-defined; float, double and long double could represent one, two or three distinct sizes OPERATORS Arithmatic Operators Operator + * / % ++ Action Subtraction Addition Multiplication Division Modulus Decrement Increment

Relational Operators Operator Action


Page 2

Niranjana.S.Karandikar

MSc-I

Roll No.12

> >= < <= == !=

Greater than Greater than or equal Less than Less than or equal Equal Not equal

Logical Operators Operator && || ! Action AND OR NOT

Decision making statements if - An if statement consists of a boolean expression followed by one or more statements. Syntax if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ } if...else statement An if statement can be followed by an optional else statement, which executes when the boolean expression is false. Syntax if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ } else {
Niranjana.S.Karandikar Page 3

MSc-I

Roll No.12

/* statement(s) will execute if the boolean expression is false */ } if...else if...else Statement An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if , else if , else statements there are few points to keep in mind: An if can have zero or one else's and it must come after any else if's. An if can have zero to many else if's and they must come before the else.

Once an else if succeeds, none of the remaining else if's or else's will be tested. if(boolean_expression 1) { /* Executes when the boolean expression 1 is true */ } else if( boolean_expression 2) { /* Executes when the boolean expression 2 is true */ } else if( boolean_expression 3) { /* Executes when the boolean expression 3 is true */ } else { /* executes when the none of the above condition is true */ }

Niranjana.S.Karandikar

Page 4

MSc-I

Roll No.12

Nested if statements It is always legal in C programming to nest if-else statements, which means you can use one if or else if statement inside another if or else if statement(s). if( boolean_expression 1) { /* Executes when the boolean expression 1 is true */ if(boolean_expression 2) { /* Executes when the boolean expression 2 is true */ } } switch statement A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case. switch(expression){ case constant-expression : statement(s); break; /* optional */ case constant-expression : statement(s); break; /* optional */ /* you can have any number of case statements */ default : /* Optional */ statement(s); }

Niranjana.S.Karandikar

Page 5

MSc-I

Roll No.12

Loops while loop in C A while loop statement in C programming language repeatedly executes a target statement as long as a given condition is true. Syntax while(condition) { statement(s); } for loop A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Syntax for ( init; condition; increment ) { statement(s); } do...while loop A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time. Syntax do { statement(s); } while( condition );

Niranjana.S.Karandikar

Page 6

MSc-I

Roll No.12

Arrays An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows: Type arrayName [ arraySize ]; Eg: #include <stdio.h> int main () { int n[ 10 ]; /* n is an array of 10 integers */ Pointers Pointers are aptly name: they "point" to locations in memory. Some C programming tasks are performed more easily with pointers, and other tasks, such as dynamic memory allocation, cannot be performed without using pointers. Syntax <variable_type> *<name>; #include <stdio.h> int main() { int x; /* A normal integer*/ int *p; /* A pointer to an integer ("*p" is an integer, so p must be a pointer to an integer) */ p = &x; /* Read it, "assign the address of x to p" */ scanf( "%d", &x ); /* Put a value in x, we could also use p here */ printf( "%d\n", *p ); /* Note the use of the * to get the value */ getchar(); }

Niranjana.S.Karandikar

Page 7

MSc-I

Roll No.12

References Balguruswami, Programming with C Mc Graw-Hill-C-The Complete reference Ritchie,R.,The C Programming Language,1988 http://www.tutorialspoint.com/cprogramming/cprogramming_tutorial.pdf http://www.cprogramming.com/ http://www.howstuffworks.com/c.htm

Niranjana.S.Karandikar

Page 8

Potrebbero piacerti anche