Introduction to C
OVERVIEW OF C
C language was originally developed for UNIX operating system. Over a period of time C started getting widespread support with increasing popularity of UNIX. It has capability to interact with hardware.
A SIMPLE PROGRAM IN C
printf(“hello this is my first program in c language”);
Above program just prints “hello this is my first program in c language “ on screen.
The first line #include<stdio.h> is a directive which is used to include the header file stdio.h in program stdio.h contains all standard input output library functions like printf(), scanf() etc.
Main() is a special function which indicates the start of program this is entry point for program, program execution starts from main(). Void is non-return type of function main(). Here main function does not return any value. Every statement in C ends with ‘;’.
VARIABLES IN C
Syntax to declare variable in C is as follows
Data _type name_of_variable1, name_of_variable1, name_of_variablen;
int marks1, marks2, marks_n;
DECISION MAKIING IN C
Syntax for if else statement is as follows
if condition1 evaluates to true then statements following if is executed else statements following else is executed.
Printf(“10 is greater than 100);
Printf(“100 is greater than 10);
2) Nested if statements
If the condition 1 evaluates to true then condition2 is evaluated if it is true then Statements1 will be executed. If condition1 is false then Statements3 will be executed.
The switch statement is useful where control flow within a program must be directed to one of several execution paths. It becomes cumbersome to use a chain of nested if() else structure.
Syntax for switch Statements is as follows
Case value1: block 1
Case value 2: block
4) GO TO
The go to statement is used to transfer control of program from one point to another point, it requires label to identify a statement where control is to be transferred.
General syntax is as follows
Label 1: statements
STRUCTURES IN C
Structures allows programmer to group data items of different data type. Structure is defined using struct keyword followed by name of the structure.
Accessing elements of structures
Struct employee e1;
OPERATORS IN C
Operators are use to perform various operation on data.
C supports following data types.
1) arithmetic operator
2) relational operator
3) logical operator
4) assignment operator
5) increment and decrement operator
6) conditional operator
7) type casting operator
POINTERS IN C
Pointers are variable that contains memory address of another variable. & this is called as memory operator.
First of all we have to declare a pointer for example we want pointer to an float number then we will
Declare it as float *p. We should use * before pointer variable. Now address of any float variable can be accessed. P = &x where x is any float variable.