Вы находитесь на странице: 1из 15

Kalasalingam Academy of Research and Education

Anand Nagar, Krishnankoil - 626126

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

TUTORIALS – ODD SEMESTER 2019-2020

Subject with code Programming in C- CSE18R153


Course/Department B.Tech /CSE
Semester / Sec I/ALL
Course Type Theory with Practical
Course Credit 3
Course Teacher Dr.K.Kartheeban

TUTORIAL-I

1. Evaluate the following Expressions


Given int a=8, b=3, c=-5;
a) 5*b+2*(a-c)
b) (a%c)*b

2. Evaluate the following Expressions


Given float x=8.8, y=3.5, z= -5.2
a) 5*y+7*(x-z)
b) 5*x/7*y

3. Evaluate the following Expressions


Given char c1=‟E‟, c2=‟5‟, c3=‟?‟
a) c1-c2+c3 b. c1%c3
b) „2‟+‟2‟ d. (c1/c2)*c3

4. Evaluate the following Expressions


and say True (or) False
Given int i=8, j=5, k
float x=0.005, y=-0.01, z
char a, b, c=‟c‟,d=‟d‟
a) x >= 0 then value of x ?
b) (2*x+y) == 0
c) (x>y)&&(i>0)&&(j<5)
d) (x>y)&&(i>0)||(j<5)
e) z=(y>=0)?y:0 then value of Z ?

5. main()
{
int x;
printf(“\n%d”,x=20,x=30,x=40);
printf(“%d”,x);
}

6. main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d%d%d%d%d",i,j,k,
l,m);
}

7. #include<stdio.h>
main()
{ int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}}

8. main()
{
int i;
for(i=0;i<=2;i++)
{
switch(i)
{
case 1: printf(“%d”,i);
case 2: printf(“%d”,i);
default: printf(“%d”,i);
} }}

9. if a=11.0 and b=10.0 then what is the output?


main()
{
float a,b,c;
scanf(“%f %f”,&a,&b);
c=a%b;
printf(“%f ”,c);
}

10. main()
{
int i=5;
printf("%d%d%d
%d%d%d",i++,i--,++i,--i,i);
}

11. main()
{
int a=10;
int b=6;
if(a=3)
b++;
printf(“%d %d\n”,a,b++);
}

12. main()
{
int x;
printf(“\n%d”,x=20,x=30,x=40);
pritnf(“%d”,x);
}
13. main( )
{
int a,b;
a=10, b=20;
printf(“%d”,a,b);
}

14. if a =5 and b=10 then what is the output?


main()
{
float a,b;
scanf(“%d %d”,&a,&b);
printf(“%f %f”,a,b);
}

15. main()
{
int a,b;
printf(“enter two numbers”);
scanf(“%d %d”,a,b);
printf(“%d + %d = %d”,a,b,a+b);
}

16. main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}

17. main()
{
int a,b;
a=10, b=20;
printf(“%d”,a,b);
}

18. main()
{ int c= - -2;
printf("c=%d",c);
}

19. #include<stdio.h>
main()
{
int a=100;
printf(“%d%d%d”, a++,a,++a);
}

20. main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}

21. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("Equal");
else
printf("Not Equal"); }

22. main()
{
int i=10;
i=!i>14;
printf(“i=%d”,i);
}

23 . main(){
int a= 0;int b = 20;
char x =1;char y =10;
if(a,b,x,y)
printf("hello"); }

24. main()
{
int y;
scanf("%d",&y);
if( (y%4==0 && y%100 != 0) ||
y%100 == 0 )
printf("%d is a leap year");
else
printf("%d is not a leap year");
}
If input given is 2000, What is the output?

25. main()
{
int x=6;
switch(x)
{
default: x+=2;
case 4: x=4;
case 5: x++;
break;
}
printf(“%d”,x);
}

26. void main()


{
int i=0;
while(i<=10)
{
if(i==4)
break;
printf(“i value is %d”,i);
i++;
}}

27. void main()


{
int i=0;
while(i<5)
{
i++;
if(i= =3)
{
continue;
}
printf(“\n i value is %d”,i);
}
}

28. #define int char


main()
{
int i=65;
printf(“sizeof(i)=%d”,sizeof(i));
}

29. main()
{
char p;
printf(“%d”,sizeof(p));
}
30. main()
{
printf(“%x”,-1<<4);
}

TUTORIAL-II

1. Find the error in each of the following program segments.


a. int sum(int x, int y)
{
int result;
result = x+y;
}
b. int sum(int n)
{
if (n= =0) return 0;
else
n+sum(n-1);
}
c. void f(float a);
{
float a;
printf(“%f”,a);
}
d. void product(void)
{
int a,b,c,result;
a=b=c=5;
result = a*b*c;
return result;
}

2. State the output of the following program segment


e. int sum(int n)
{
if(n-1)
return n;
else
return (n+sum(n-1));
}
main()
{
printf(“%d”,sum(6));
}
a) 10 b) 16 c) 14 d) 15
f. void swap(int,int);
main()
{
int x=20,y=10;
swap(x,y);
printf(“%d, %d”,y,x+2); }
void swap(int x, int y)
{
int temp;
temp = x;
x=y;
y=temp;
}
a) 10,20 b) 20,12
c) 22,10 d) 10,22
g. int func(int x)
{
if (x<=0) return (1);
return func(x-1)+x;
}
main()
{
printf(“%d\n”,func(5));
}
a) 12 b) 16 c) 15 d) 11
h. void e(int);
main()
{
int a;
a = 3; e(a);
}
void e(int n)
{
if(n>0) {
e(--n); printf(“%d”,n)
e(--n); }
}
a) 0 1 2 0 b) 0 1 2 1
c) 0 2 0 1 d) 0 2 1 1

a. main()
{
extern int i;
i=20;
printf("%d",i);
}
b. main()
{
extern out;
printf("%d", out);
}
int out=100;
c. main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main(); }
a. main()
{
while(strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”);
}
b. main()
{
char str1[] = {„s‟,‟o‟,‟m‟,‟e‟};
char str2[] = {„s‟,‟o‟,‟m‟,‟e‟,‟\0‟};
while(strcmp(str1,str2))
printf(“Strings are not equal\n”);
}
c. #include<stdio.h>
main()
{
if(“string”==”string”)
printf(“Both the strings are Equal”);
else
printf(“Both the strings are Not Equal”);
}
d. main()
{
char a[4]="HELL";
printf("%s",a);
}
e. void main()
{
char a[]="12345\0";
int i=strlen(a);
printf("here in 3 %d\n",++i);
}

a. main()
{
int a[]={10,20,30};
int *ip, i;
ip=a;
for(i=0;i<2;i++)
{
printf(“%d”,*ip);
}
}
a. 10 20 30 b. 10 20 c. 1 2 3 d. error

b. main()
{
char a[4]={„H‟,‟E‟,‟L‟,‟L‟,‟\0‟};
printf("%s",a);
}

a. HEL b. HELL
c. compiler error ( too many values in initialization )
d. none of the above
c. main()
{
char a[4]="HELL";
printf("%s",a);
}
a. HEL b. HELL c. compiler error d. none of the above

d. What shall be the output of the following code?


void main()
{
int a[3][2]={ 1,2,
5,7,
6,8};
printf("\n%d", ((a+1)-(&a+1)));
}
A. 0 B.-16
B. C.-2 D.-8
e. Find out the output of the following program :
main()
{
int a[5] = {1, 2, 3, 4};
printf(“%d %d %d %d”, 0[a],
1[a], 2[a], 3[a]);
}
A) compiler error
B) linker error
C) 1 2 3 4
D) None of the Above

TUTORIAL-III

1. main()
{
int a[]={10,20,30};
int *ip, i;
ip=a;
for(i=0;i<2;i++)
{
printf(“%d”,*ip);
}
}
a. 10 20 30 b. 10 20
c. 1 2 3 d. error

2. Find the output.


#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
a. RamcoSystems b. Ramco Systems
c. Systems Ramco d. Error

3. Find the output of the following program


void main()
{
int x=5, *p;
p=&x
printf("%d ",++*p);
}
(a) 5 (b) 6
(c) 0 (d) none of these

4. void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=&sum;
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}
a. 10, 20,20 b. 20 20 20
c. 20 10 10 d. 20 20 10

5. If starting address of array b is 2000 then what is the output?


main()
{
int b[] = {100,200,300};
int *ip, i;
ip=b;
for(i=0;i<3;i++)
{
printf(“Stored at %u”, ip);
}
}
a.2000 2001 2002 b.2000 2002 2004
c. Compiler error d.No error

6. What is the output?


void display(int *);
void main()
{
int i,a[]={1,2,3};
for(i=0;i<3;i++)
{
display(&a[i];
}
for(i=0;i<3;i++)
{
printf(”%d”,a[i]);
}
}
void display(int *ip)
{
*ip=*ip+5;
}
a. 1 2 3 b. 6 7 8
c. Address will be printed
d. compiler error

7. What is the output?


void display(int);
void main()
{
int i,a[]={1,2,3};
for(i=0;i<3;i++)
{
display(a[i]);
}
for(i=0;i<3;i++)
{
printf(”%d”,a[i]);
}
}
void display(int m)
{
m=m+10;
}
a. 1 2 3 b. 11 12 13
c. Address will be printed d. compiler error

8. main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[i],
*(s+i),*(i+s),i[s]);
}
a. man
b. mmmm
c. mmmm
aaaa
nnnn
d. Compiler Error

9. main()
{
char *p;
printf("%d%d",
sizeof(*p),sizeof(p));
}
a. 1 2 3 b. 1 2
c. compiler error
d. None of the above

10. #define int char


main()
{
int i=65;
printf("sizeof(i)=%d",sizeof(i));
}
a. sizeof(i)=1 b. sizeof(i)=2
c. Compiler error d. None

11. #include<stdio.h>
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
a. 100 b. abc c.77 d.101

12. #define square(x) x*x


main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
a. 16 b. 4
c. 64 d. None of the above

13. main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
}
a. Hello b. H c. He d. Hell

14. main( )
{
int a[2][3][2]=
{{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf(“%u%u%u %d \n”,a,*a,**a,***a);
printf(“%u%u%u%d\n”,a+1,*a+1,**a+1,***a+1);
}
a. 100, 100, 100, 2
114, 104, 102, 3
b. 100,100,100,100
c. 101,102, 200, 202
d. 100, 101,102,103

15. main( )
{
static int a[ ] = {0,1,2,3,4};
int *p[ ] = {a,a+1,a+2,a+3,a+4};
int **ptr = p;
ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*++ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
++*ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
}
a. 111
222
333
344
b. 1234
1234
1234
1234
c.1234
d.1111

16. main( )
{
void *vp;
char ch = „g‟, *cp = “goofy”;
int j = 20;
vp = &ch;
printf(“%c”, *(char *)vp);
vp = &j;
printf(“%d”,*(int *)vp);
vp = cp;
printf(“%s”,(char *)vp + 3);
}
a. g20fy b.20
c. fy d. None of the above

17. main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}
a. 100 b.10
c.Compiler error d. None

18. # include<stdio.h>
aaa()
{
printf("hi");
}
bbb()
{
printf("hello");
}
ccc()
{
printf("bye");
}
main()
{
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2]();
}
a.3 b. hello
c. bye d. None of the above
19. main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
}

a. 300 b. 3000 c. 100 d. Error

20. main()
{
int a[10];
printf("%d",*a+1-*a+3);
}
a. 2 b. 4 c.3 d. Error
21. If address of a is 4000 then what is the output?
main()
{
int a=5,*p;
p=&a;
p=p+2;
printf(“%u”,p);
printf(“%u”,++p)
}
a.4000 4001 b. 4001 4002
c. 4002 4004 d. 6 7
Course Coordinator Module Coordinator

Programme Coordinator HOD/CSE

Вам также может понравиться