Intermediate c programming

Page 1

INTERMEDIATE C 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 • C uses 32 keyword • have fixed meaning and cannot be changed

Keywords auto break case char const continue default do

double else enum extern float for goto if

int long register return short signed sizeof static

struct switch typedef union unsigned void volatile while

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 Addition + Subtraction Multiplication * Division / Modulus %

Algebraic C expression expression f+7 f+7 p窶田 p-c bm b*m x/y x/y 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 Meaning of C condition condition

== !=

x == y x != y

x is equal to y x is not equal to y

> <

> <

x > y x < y

x is greater than y x is less than y

>=

>=

x >= y

<=

<=

x <= y

x is greater than or equal to y x is less than or equal to y

Equality Operators

= not = Relational Operators

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 take any decision according to the condition or user requirement. These conditions are used by using ‘if’ statement. We can have four types of conditional statements • 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 the condition 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 }

infobizzs.com

se


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.