intermediate c programming

21
INTERMEDIATE C PROGRAMMING LANGUAGE TUTORIAL infobizzs.com

Upload: steve-fort

Post on 22-Jul-2016

231 views

Category:

Documents


0 download

DESCRIPTION

Intermediate Information about C programming language..

TRANSCRIPT

INTERMEDIATEC PROGRAMMING LANGUAGE TUTORIAL

infobizzs.com

VARIABLES• Variable names correspond to locations in the computer's

memory

• Data name that may be used to store a data value

• It may take different values at different times during execution

• Eg:

• char x;

• char y = ‘e’;

infobizzs.com

• Rules

• Must begin with a letter(), some system permits underscore as

first character.

• Length should be not more than 8 characters

• Uppercase and lowercase are significant, (i.e.) total and TOTAL

are different

• Variable should not be a keyword

• White space is not allowed

infobizzs.com

C IS CASE SENSITIVE

C is case sensitive: it distinguishes between UPPER case (CAPITAL) and lower case (small) letters.

Keywords in C — for example, the keyword int — MUST be in lower case. For example:

#include <stdio.h>

int main ()

{ /* main */int height_in_cm;

height_in_cm = 160;

printf("My height is %d cm.\n",height_in_cm);

} /* main */

infobizzs.com

C TOKENS• Keywords

• Identifiers

• Constants

• Strings

• Special Symbol

• Operators

• Identifiers

• Names of arrays, function and variable

Infobizzs.com

Keywords

auto double int struct

break else long switch

case enum register typedef

char extern return union

const float short unsigned

continue for signed void

default goto sizeof volatile

do if static while

• Keywords

• C uses 32 keyword

• have fixed meaning and cannot be changed

infobizzs.com

• Constants

• Quantity that does not change is called a constant.

• Types

• Numeric constants

• Integer constants – 123, -33

• Real constants – 0.992, 3.5e2

• Character constants

• Single character constants – ‘5’, ‘a’

• String Constants – ‘Hello’, ‘1999’

infobizzs.com

Backslash Characters Constants

• \n – Newline

• \b – Backspace

• \f – Form feed

• \t – Tab or horizontal tab

• \a – Audible alert

• \r – Carriage return

• \v – Vertical Tab

• \’ – Single Quote

• \” – Double Quote

• \? – Question Mark

• \\ - Backslash

• \0 - Null

infobizzs.com

OPERATORS IN C LANGUAGE

There are following types of operators to perform different types of operations in C language.

1) Arithmetic Operators

2) Relational Operators

3) Shift Operators

4) Logical Operators

5) Bitwise Operators

6) Ternary or Conditional Operators

7) Assignment Operator

8) Misc Operator

infobizzs.com

ARITHMETIC OPERATORS

C operation

Arithmetic

operator

Algebraic

expression

C expression

Addition + f + 7 f + 7

Subtraction - p – c p - c

Multiplication * bm b * m

Division / x / y x / y

Modulus % r mod s r % s

infobizzs.com

• Equality and Relational Operators

Standard algebraic

equality operator or

relational operator

C equality or

relational

operator

Example of C

condition

Meaning of C

condition

Equality Operators

= == x == y x is equal to y

not = != x != y x is not equal to y

Relational Operators

> > x > y x is greater than y

< < x < y x is less than y

>= >= x >= y x is greater than or

equal to y

<= <= x <= y x is less than or

equal to y

infobizzs.com

Logical Operators:

&& logical And

|| logical Or

! logical Not

Bitwise Operators

& bitwise And

| bitwise Or

^ bitwise Xor

~ bitwise Not

<< shift left

>> shift right

infobizzs.com

SAMPLE C PROGRAM /* Program for multiplication of two variables */

#include< stdio.h>

#include < conio.h>

void main()

{

int a,b,c;

clrscr();

printf(“Enter two numbers”);

scanf(“%d%d”,&var1,&var2);

c=a*b;

printf (“\n Multiplication of two numbers is %d ”,c);

getch();

}

infobizzs.com

• OUTPUT:

Enter two numbers: 12 3

Multiplication of two numbers is 36

infobizzs.com

CONTROL STATEMENTS

• These statements are used to control the flow of program by using these statements. We can have four types of control statements:-

• decision making

• case control statement or switch statement

• looping / iteration statement

• jump / branching statement

infobizzs.com

Control statement in C language:-

1) if-else

2) switch

3) loops

4) do-while loop

5) while loop

6) for loop

7) break

8) continue

infobizzs.com

DECISION MAKING

• These statements are used when we want to takeany decision according to the condition or userrequirement. These conditions are used by using ‘if’statement. We can have four types of conditionalstatements

• if

• if-else

• if – else if

• nested if

infobizzs.com

• if

if statement is simple decision making statement,which is used to take any decision when thecondition is true.

if (statement)

{

Statement;

}

• if (expression / condition)

Statement;

infobizzs.com

• If-else

This statement is used to make decision in C language. If the given condition is true then the cursor will move to the true portion else it will move to the false portion.

if (condition)

{

Statement;

}

else

{

Statement;

}

infobizzs.com

If else-if

if (condition)

{

Statement;

}

else if (condition)

{

Statement;

}

else if (condition)

{

Statement;

}

else

{

Statement;

} infobizzs.com

if else-if ladder Statement:-

Syntax:

if(condition1){

//code to be executed if condition1 is true

}else if(condition2){

//code to be executed if condition2 is true

}

else if(condition3){

//code to be executed if condition3 is true

}

...

else{

//code to be executed if all the conditions are fal se

}

infobizzs.com