Академический Документы
Профессиональный Документы
Культура Документы
K V Ranga Rao
Asst.professor, CSE
B Ken Thompson
1970
Traditional C
1972 Dennis Ritchie
ANSI C
1989 ANSI Committee
CONSTANTS
Single String
Integer Real
character constants
ex: m=5;
y=++m;
in this case value of y will be 6. as m value is incemented
first and assigned to y.
(a)16VIGNANUNIVERSITY
(b)VIGNANUNIVERSITY16
(c)Garbage VIGNANUNIVERSITY
(d)Compiler error
K V RANGA RAO V FSTR University 02/27/17
Evaluation of arithmetic expression
An arithmetic expression is a combination of variables,
constants and operators arranged as per syntax of the
language.
Expressions are evaluated using assignment statement
of the form variable= expression
The expression is evaluated first and the result replaces
the previous value of the variable on the left hand side.
+,-(unary),++,
--, !, ~, *(pointer), R to L 2
&, sizeof, (type)
*,/, % L to R 3
+,- L to R 4
<<, >> L to R 5
<, <=, > >= L to R 6
++ , != L to R 7
K V RANGA RAO V FSTR University 02/27/17
Operator associativity precedence
& L to R 8
^ L to R 9
| L to R 10
&& L to R 11
|| L to R 12
?: R to L 13
=,*=,/=,%-,+=
-=,&=,^=,|=,<<=
>>= R to L 14
, L to R 15
K V RANGA RAO V FSTR University 02/27/17
The expression a= 30 * 1000 + 2768 evaluates to
(a) 32768 (b) -32768 113040 (d) 0
the expression x = 4 + 2 % -8 evaluates
(a) -6 (b) 6 4 (d) none
the expression a= 7/ 22 * (3.14 +2) * 3/5 evaluates to
(a) 8.28 (b) 6.28 3.14 (d) 0
which of the following arithmetic expressions are valid.
(a) 25/3%2 -14%3 (e) 7.5 %3
(b) +9/4 + 5 (d) 15.25 +-5.0 (f) (5/3)*3+5%3
What will be the output of the following arithmetic expression ?
5+3*2%10-8*6
float
double
long double
un signed char %c
double %lf
K V RANGA RAO V FSTR University 02/27/17
User Defined data types
typedef
#include<stdio.h>
int main(){
float x=12.25, y=13.65;
if(x=y)
printf("x and y are equal");
else
printf("x and y are not equal");
1.if(c=1)
2.if(c!=3)
3.if(a<b)then
4.if(c==1)
(a) 1 only (b) 1&3 (c) 3 only (d) All of the above
statement- x;
K V RANGA RAO V FSTR University 02/27/17
Switch statement
Switch(expression)
{
case value1: statement-1;
break;
case value n : statement n;
break;
default: default statement;
break;
}
K V RANGA RAO V FSTR University 02/27/17
What will be the output of the following program ?
#include <stdio.h>
void main()
{ int a = 2;
switch(a)
{
case 1:
printf("goodbye"); break;
case 2:
continue;
case 3:
printf("bye");
}
}
a) error b) goodbye c) bye d) bye goodbye
K V RANGA RAO V FSTR University 02/27/17
Point out the error, if any, in the program.
main()
{
int i=1;
switch(i)
{
printf(hello);
case 1: printf ( Vignan );
break;
case 2: printf(university);
break;
}
}
K V RANGA RAO V FSTR University 02/27/17
Point out the error, if any in the program
main()
{
int i=1;
switch(i)
{
int n,sum=1;
switch(n)
{
case 2:sum=sum+2;
case 3:sum*=2;
break;
default: sum=0;
}
If n=2, what is the value of sum
while (condition)
{
Body of the loop
}
* While is an entry controlled loop. The test condition
is evaluated first and if the condition is true, statements
in the body of the loop will be executed. Then again
the condition is evaluated and if it is true again body of
the loop will be executed. This process will be
K V RANGA RAO V FSTR University 02/27/17
continued until the condition becomes false
What will be the output of the following.
void main()
{
int i=1;
while(i<=10);
{
printf(%d,i);
i=i+1;
}
getch();
}
1-D arrays
2-D arrays
Multi dimensional arrays
#include<stdio.h>
void main()
{
int a[3][4];
fun(a);
}
A. void fun(int p[][4]) { } B. void fun(int *p[4]) { }
C. void fun(int *p[][4]) { } D. void fun(int *p[3][4]) { }
Ex:
main()
{
int x;
x=add(10,5); /* function call */
printf( %d ,x);
}
Storage : memory
Scope: global
struct abc
{
int a;
float b;
char c;
} e, *p;
(*p).a=5;
p->c=a;
union abc
{
int x;
float y;
char z;
};
main()
{
int x=5, *p;
p=&x
printf("%d",++*p);
}
(a) 5 (b) 6 (c) 0 (d) none of these
a. malloc()
b. calloc()
c. free()
d. realloc()