Review Of C programming

It is easy to learn. It has a large library of functions.INTRODUCTION In 1972. It has a rich set of operators to solve scientific and business applications. C is a machine independent and highly portable language. User can create their own functions and add to C library. WHY IS C LANGUAGE POPULAR? 1. 6. 3. 4. BYTES and ADDRESSES. 2. the Dennis Ritchie at Bell Labs developed C language incorporating the best feature of both BCPL and “B” languages. C language allows manipulation of BITS. 5. .

decision statements etc. that you have learnt in your previous year. variables. The review of C programming section will definitely help you to brush up your C knowledge acquired so far. This chapter gives you an overview of C language and tells about various components of a C program.C BASICS From this section onwards we discuss Review of C programming. . data types. such as character set. basic input-output statements. keywords. constants.

Variables 4. The character set 2. Data types . Operators 3. Tokens a.C LANGUAGE COMPONENTS The four main components of C language are: 1. Constants d. Identifiers c. Keywords b.

*. (comma) .Operators An operator is a symbol that tells the computer to perform certain mathematical or logical manipulation on data stored in variables. 6./.<=.>=. . &. || ?: ++.|.%= = sizeof. 9. Arithmetic operators Relational operators Logical operators Conditional operators (Ternary) Increment and decrement (Unary) Bitwise operators Shorthand operators Assignment operators Special operator +.<<.-!. C operators can be classified into the following types 1.-. 2. 5. 8.>. 4. The variables that are operated are termed as operands.!= !. &&. 7.^.~. 3.*=.==.-+.>> +=./=.% <.

Each variable in reality represents the name of a memory location in which a value can be stored. functions. Variables are nothing but identifiers. files and may other such element used in a program. which are used to identify various programming elements. arrays. unions. Example: Here are some examples of valid variable names Name years sum stud_name total num salary acc_no . They are used to denote constants. structures.Variables A variable is an object or element that may take on any value of a specified type.

short int and unsigned) ii. references. b. pointers. constants. Memory allocated for it. The range of values that can be used. Derived data types (Derived data include arrays. float. The possible operations that can be performed. Simple or Fundamental data types (int. unions and enumerations) . d. c.double. functions.Data types Data types indicate the type of data a variable can have. structures. Its representation in the program. Data types are classified as i. char. long int . a. A data type requires us to know.

THE STRUCTURE OF A C PROGRAM Every C program includes the following components : i ii iii iv v Preprocessor directives main( ) A pair of flower brackets { } Declarations and statements User created sub-programs or functions .

#include <stdio. printf (“ Area = %f”.c).1415 main( ) { int float r. printf (“Enter the radius of a circle”). } . a). a = PI * r * r. c = 2 * PI * r.Program: The following program illustrates the structure of a C program. a. printf (“Circumference = %f”.c. scanf (“%d”.h> #define PI 3. &r).

ii.Console I/O functions i. Formatted Console I/O Unformatted Console I/O .

scanf(“%d”. scanf(“%s%s”.name. ii. .Formatted Console I/O printf(format control string.address). argument list) Example i. scanf(“%c”. Specifier %c %d %f %s %x %u %ld Meaning print a character print a signed decimal integer print signed float value print a string print hexadecimal integer print an unsigned integer print a signed long decimal integer scanf(format control string. &ch).&n). iii. argument list).

character output functions a) puts( ) . All the unformatted console I/O functions are defined in stdio. character input functions a) getch( ) and getche( ) b) getchar( ) ii.h header file. character string output functions a) gets( ) iv.Unformatted Console I/O Unformatted console I/O functions cannot control the format of reading and writing the data.character output functions a) putchar( ) iii. i.

ii. iii. i.TYPES OF STATEMENTS They are. v. vi Null statement Expression statement Compound statement Selection statement Looping statement Jumping statement . iv.

if-else statement Format: if (expression) statement1. else statement2.Selection (conditional) statement The selection statements allow to choose the set-of-instructions for execution depending upon an expression's truth value. . if statement Format: if ( expression ) statement.

2. . 4.nested-if statement Format: if (expression1) if (expression 2) statement else statement else if (expression 3) statement else statement 1. 3.

.. default : default block. break..THE switch STATEMENT switch(control expression) { case case-label-1 : statement-list-1. } . break.. case case-label-2 : statement-list-2. ..

A loop is a program construct that causes a statement to be executed again and again. The process of repeating the execution of a certain set of statements again and again is termed as looping. C has several such statements that can be used to form loops they are i. ii. while statement do-while statement for statement . iii.Looping statement The concept of loops is fundamental to structured programming.

.. ……. . Statements 2.THE while STATEMENT while (test condition) { Statement 1. Statements n+1. THE do-while STATEMENT do { Statements 1. } while (test condition). } Statement n+1. Statement 2. …….

. Statements 2. } Statements n+1.. Expression 1 represents the initialization expression. 3.Expression 3) { Statements 1. Expression 2 represents the expression for the final condition.THE for STATEMENT for(Expression 1.Expression 2. 2. Expression 3 represents the increment or decrement expression. ……. Where 1.