c programs pbq final

Post on 29-Jul-2015

141 Views

Category:

Education

9 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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;}

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;}

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;}

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;}

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();}

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

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; }

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

}

10.What is the output of the following program?

main(){

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

printf(“%u ”,i);}

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

}

12.What is the output of thefollowing program?

main(){

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

}

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

}

14.What is the output of the following program?

main(){

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

}

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

16. What is the output of the following program?

main(){

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

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

17. What is the output of the following program?

main(){

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

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

18.What is the output of the following program?

main(){

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

}

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

}

21. What is the output of thefollowing program?

void main(){

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

printf(“%d”, i);}

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

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”);}}

24.What is the output of the following program?

main(){

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

{int i=20;

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

25.What is the output of thefollowing program?

main(){

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

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

26. What is the output of thefollowing program?

main(){

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

}

27.What is the output of thefollowing program?

void main(){

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

}

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

}

29.What is the output of the following program?

main(){

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

}

30. What is the output of thefollowing program?

#define int char

main(){

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

}

top related