Você está na página 1de 33

Overview Of C Programming

Niranjana.S.Karandikar MSc-I Roll No.12

Introduction Compiler vs Interpreter Basic structure of a C program Data Type Functions Operators Decision Making Statements Loops Arrays Pointers

Contents

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
Compiler:

Source Code
Interpreter

reads the source code of your program one line at a time,performing the specific instructions contained in that line

Object Code

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 short signed return Size of static

struct switch typedef union unsigned void volatile while

Data Types
A set of values that a variable can store along with a set of operations that can be performed on that variable. 5 Data Types
char int float ----06 digits of precision double -10 digits of precision

operators
Arithmatic Operators o Operator Action Subtraction + Addition * Multiplication / Division % Modulus Decrement ++ Increment

Relational Operators
Relational Operators o Operator Action > 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
Syntax if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ }

if...else statement
Syntax
if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ } else { /* statement(s) will execute if the boolean expression is false */ }

if...else if...else Statement


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 */ }

Nested if statements
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
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); }

Loops

Break and Continue

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 );

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. 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(); }

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

Thank You

Questions?????

Você também pode gostar