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

#include<stdio.h>

Void main()

{

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;

Example

int marks1, marks2, marks_n;

 

Introduction to C

 

DECISION MAKIING IN C

 

1)If Else

Syntax for if else statement is as follows

If(condition)

{

–statements–

}

Else

{

–Statements–

}

if condition1 evaluates to true then statements following if is executed else statements following else  is executed.

Example

If(10>100)

{

Printf(“10 is greater than 100);

}

Else

{

Printf(“100 is greater than 10);

}

 

2) Nested if statements

if(condition1)

{

if(condition2)

{

Statements1

}

Else

{

Statements2

}

 

}

else

{

Statements3

}

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.

 

3) SWITCH

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

Switch (expression)

{

Case value1: block 1

Break;

Case value 2: block

Break;

Default:

Default statements

Break;

}

 

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

Goto label1

——

——

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.

For example

Struct employee

{

int id;

Char name[50];

Float salary;

}

Accessing elements of structures

Struct employee e1;

e.id;

e.name;

e.salary;

 

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.

For more reading about technology news in singapore and seo to online marketing do view more about other pages.

Sourabh Bhunje

Sourabh Bhunje, B.E. IT from Pune University. Currently Working at Techliebe. Professional Skills: Programming - Software & Mobile, Web & Graphic Design, Localization, Content Writing, Sub-Titling etc. http://techliebe.com/about-us

Leave a Reply