c programs pbq final

31

Upload: azad-public-school

Post on 29-Jul-2015

142 views

Category:

Education


9 download

TRANSCRIPT

Page 1: C programs pbq final
Page 2: C programs pbq final

1. What will be output when you will execute following c code?#include<stdio.h>

int main(){    printf("%d\t",sizeof(6.5));

    printf("%d\t",sizeof(90000));  printf("%d",sizeof('A'));

    return 0;}

Page 3: C programs pbq final

2.What will be output when you will execute following c code?

#include<stdio.h>int main(){

    signed x;    unsigned y;

    x = 10 +- 10u + 10u +- 10;    y = x;

    if(x==y)         printf("%d %d",x,y);

    else if(x!=y)        printf("%u %u",x,y);

    return 0;}

Page 4: C programs pbq final

3.What will be output when you will execute following c code?#include<stdio.h>

int main(){    double num=5.2;

    int  var=5;    printf("%d\t",sizeof(!num));

    printf("%d\t",sizeof(var=15/2));   printf("%d",var);

    return 0;}

Page 5: C programs pbq final

4.What will be output when you will execute following c code?

#include<stdio.h>enum A{    x,y=5,

    enum B{         p=10,q

    }varp;}varx;

int main(){   printf("%d%d",x,varp.q);

    return 0;}

Page 6: C programs pbq final
Page 7: C programs pbq final

6.What will be the output of the following.#include<stdio.h>

#include<conio.h>void main()

{int a=1,b=1,c=0,i;

clrscr();printf("%d\t%d\t",a,b);

for(i=0;i<=10;i++){

c=a+b;

if(c<100){printf("%d\t",c);}a=b;b=c;}getch();}

Page 8: C programs pbq final

7.What will be the output of the following code.#include<stdio.h>

#include<conio.h>void main()

{int uabs(int), x;

clrscr();printf(“enter a negative value:”);

scanf(“%d”, x);x=uabs(x);

printf(“X=%d”, x);return 0;

}

uabs(int y){if(y<0)return(y*-1);elsereturn(y);}

Page 9: C programs pbq final

8.What will be the content of 'file.c' after executing the following program?

#include<stdio.h>int main(){ FILE *fp1, *fp2; fp1=fopen("file.c", "w"); fp2=fopen("file.c", "w"); fputc('A', fp1); fputc('B', fp2); fclose(fp1); fclose(fp2); return 0; }

Page 10: C programs pbq final

9.What is the output of the following program?

void main(){

static int i=i++, j=j++, k=k++;printf(“i = %d j = %d k = %d”, i, j, k);

}

Page 11: C programs pbq final

10.What is the output of the following program?

main(){

unsigned int i=10;while(i-->=0)

printf(“%u ”,i);}

Page 12: C programs pbq final

11.What is the output of thefollowing program?#include<conio.h>

main(){

int x,y=2,z,a;if(x=y%2) z=2;

a=2;printf(“%d %d”,z,x);

}

Page 13: C programs pbq final

12.What is the output of thefollowing program?

main(){

int a[10];printf(“%d”,*a+1-*a+3);

}

Page 14: C programs pbq final

13. What is the output of the following program?

#define prod(a,b) a*bmain(){

int x=3,y=4;printf(“%d”,prod(x+2,y-1));

}

Page 15: C programs pbq final

14.What is the output of the following program?

main(){

unsigned int i=65000;while(i++!=0);printf("%d",i);

}

Page 16: C programs pbq final

15. What is the output of the following program?

main(){

float f=5,g=10;enum{i=10,j=20,k=50};

printf(“%d\n”,++k);printf(“%f\n”,f<<2);printf(“%lf\n”,f%g);

printf(“%lf\n”,fmod(f,g));}

Page 17: C programs pbq final

16. What is the output of the following program?

main(){

signed char i=0;for(;i>=0;i++) ;

printf(“%d\n”,i);}

Page 18: C programs pbq final

17. What is the output of the following program?

main(){

unsigned char i=0;for(;i>=0;i++) ;

printf(“%d\n”,i);}

Page 19: C programs pbq final

18.What is the output of the following program?

main(){

char *p = “ayqm”;printf(“%c”,++*(p++));

}

Page 20: C programs pbq final
Page 21: C programs pbq final

20.What is the output of the following program?

main(){

char str1[] = {‘s’,‘o’,‘m’,‘e’};char str2[] = {‘s’,‘o’,‘m’,‘e’,‘\0’};

while (strcmp(str1,str2))printf(“Strings are not equal\n”);

}

Page 22: C programs pbq final

21. What is the output of thefollowing program?

void main(){

static int i;while(i<=10)(i>2)?i++:i--;

printf(“%d”, i);}

Page 23: C programs pbq final

22.What is the output of the following program?

main(){

register int a=2;printf(“Address of a = %d”,&a);

printf(“Value of a = %d”,a);}

Page 24: C programs pbq final

23. What is the output of thefollowing program?

main(){

float i=1.5;switch(i)

{case 1: printf(“1”);case 2: printf(“2”);

default : printf(“0”);}}

Page 25: C programs pbq final

24.What is the output of the following program?

main(){

extern i;printf(“%d\n”,i);

{int i=20;

printf(“%d\n”,i);}}

Page 26: C programs pbq final

25.What is the output of thefollowing program?

main(){

int i = 257;int *iPtr = &i;

printf(“%d %d”, *((char*)iPtr), *((char*)iPtr+1));}

Page 27: C programs pbq final

26. What is the output of thefollowing program?

main(){

char a[4]=“HELLO”;printf(“%s”,a);

}

Page 28: C programs pbq final

27.What is the output of thefollowing program?

void main(){

int const * p=5;printf("%d",++(*p));

}

Page 29: C programs pbq final

28.What is the output of the following program?

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]);

}

Page 30: C programs pbq final

29.What is the output of the following program?

main(){

char *p;printf(“%d %d ”,sizeof(*p),sizeof(p));

}

Page 31: C programs pbq final

30. What is the output of thefollowing program?

#define int char

main(){

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

}