16
(1) What will be output of following c code? #include<stdio.h> extern int x; int main(){ do{ do{ printf("%o",x); } while(!-2); } while(0); return 0; } int x=8; (2) What will be output of following c code? #include<stdio.h> int main(){ int i=2,j=2; while(i+1?--i:j++) printf("%d",i); return 0; }

· Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

  • Upload
    vukiet

  • View
    225

  • Download
    5

Embed Size (px)

Citation preview

Page 1: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

(1)

What will be output of following c code?

#include<stdio.h>extern int x;int main(){    do{        do{             printf("%o",x);         }         while(!-2);    }    while(0);    return 0;}int x=8;

(2)What will be output of following c code?        #include<stdio.h>int main(){    int i=2,j=2;    while(i+1?--i:j++)         printf("%d",i);    return 0;}

(3)What will be output of following c code?

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

Page 2: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

    int x=011,i;    for(i=0;i<x;i+=3){         printf("Start ");         continue;         printf("End");    }    return 0;}

(4)What will be output of following c code?

#include<stdio.h>int main(){    int i,j;    i=j=2,3;    while(--i&&j++)         printf("%d %d",i,j);    return 0;}

(5)What will be output of following c code?

#include<stdio.h>int main(){    static int i;    for(++i;++i;++i) {         printf("%d ",i);

Page 3: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

         if(i==4) break;    }    return 0;}

(6)What will be output of following c code?

#include<stdio.h>int main(){    int i=1;    for(i=0;i=-1;i=1) {         printf("%d ",i);         if(i!=1) break;    }    return 0;}

(7)What will be output of following c code?

#include<stdio.h>int main(){    for(;;) {         printf("%d ",10);    }    return 0;}

(8)What will be output of following c code?        #include<stdio.h>

Page 4: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

int r();int main(){    for(r();r();r()) {         printf("%d ",r());    }    return 0;}int r(){    int static num=7;    return num--;}

(9)What will be output of following c code?        #include<stdio.h>#define p(a,b) a##b#define call(x) #xint main(){    do{         int i=15,j=3;         printf("%d",p(i-+,+j));    }    while(*(call(625)+3));    return 0;}

(10)

#include<stdio.h>int main(){    int i;    for(i=0;i<=5;i++);    printf("%d",i)

Page 5: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

    return 0;}

12)What will be output of following c code?

#include<stdio.h>char _x_(int,...);int main(){    char (*p)(int,...)=&_x_;    for(;(*p)(0,1,2,3,4); )         printf("%d",!+2);    return 0;}char _x_(int a,...){    static i=-1;    return i+++a;}

(13)What will be output of following c code?

#include<stdio.h>int main(){    int i;    for(i=10;i<=15;i++){         while(i){             do{                 printf("%d ",1);                 if(i>>1)                      continue;             }while(0);             break;         }    }    return 0;}

Page 6: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

(14)How many times this loop will execute?

#include<stdio.h>int main(){    char c=125;    do         printf("%d ",c);    while(c++);    return 0;}

(15)What will be output of following c code?        #include<stdio.h>int main(){    int x=123;    int i={         printf("c" "++")    };    for(x=0;x<=i;x++){         printf("%x ",x);    }    return 0;}

16 What is the output of this C code?

    (Assuming size of int be 4)

1. #include <stdio.h>2. struct temp3. {4. int a;5. int b;6. int c;7. } p[] = {0};

Page 7: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

8. main()9. {10. printf("%d", sizeof(p));11. }

a)4

b)12

c)16

d)Can’t be estimated due to ambigous initialization of array

17. What is the output of this C code?

1. #include <stdio.h>2. struct student3. {4. char *name;5. };6. struct student s[2];7. void main()8. {9. s[0].name = "alan";10. s[1] = s[0];11. printf("%s%s", s[0].name, s[1].name);12. s[1].name = "turing";13. printf("%s%s", s[0].name, s[1].name);14. }

a) alan alan alan turing

b) alan alan turing turing

c) alan turing alan turing

d) Run time error

18. What is the output of this C code?

1. #include <stdio.h>2. struct student3. {4. char *name;5. };6. struct student s[2], r[2];7. void main()8. {9. s[0].name = "alan";10. s[1] = s[0];11. r = s;12. printf("%s%s", r[0].name, r[1].name);13. }

Page 8: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

a) alan alan

b) Compile time error

c) Varies

d) Nothing

19. What is the output of this C code?

1. #include <stdio.h>2. struct student3. {4. char *name;5. };6. void main()7. {8. struct student s[2], r[2];9. s[1] = s[0] = "alan";10. printf("%s%s", s[0].name, s[1].name);11. }

a) alan alan

b) Nothing

c) Compile time error

d) Varies

20. What is the output of this C code?

1. #include <stdio.h>2. struct student3. {4. };5. void main()6. {7. struct student s[2];8. printf("%d", sizeof(s));9. }

a)2

b)4

c)8

d) 0

. 21)Comment on the output of following C program?

1. #include <stdio.h>2. main()3. {4. int a = 1;

Page 9: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

5. printf("size of a is %d, ", sizeof(++a));6. printf("value of a is %d", a);7. };

a. size of a is 4, value of a is 1

b. size of a is 4, value of a is 2

c. size of a is 2, value of a is 2

d. size of a is 2, value of a is 2

22. Which among the following is right?

a. sizeof(struct stemp*) > sizeof(union utemp*) > sizeof(char *)

b. sizeof(struct stemp*) < sizeof(union utemp*) < sizeof(char *)

c. sizeof(struct stemp*) = sizeof(union utemp*) = sizeof(char *)

d. The order Depends on the compiler

23. Comment on the following C code?

1. #include <stdio.h>2. printf("%d", sizeof(strlen("HELLOWORLD")));

a. Output, 4

b. Output, 10

c. Output, 16

d. Error, sizeof cannot evaluate size of a function.

24. Which of the following cannot be used inside sizeof?

a.pointers

b.functions

c.macro definition

d.None of the mentioned

25. Comment on the following C code?

1. #include <stdio.h>2. (sizeof double = 8, float = 4, void = 1)3. #define PI 3.144. int main()5. {6. printf("%d", sizeof(PI));7. }

a. Output is 8

b. Output is 4

c. Output is 1

Page 10: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

d. Error, we can’t use sizeof on macro-definitions

. 26)What is the output of this C code?

1. #include <stdio.h>2. struct p3. {4. int x;5. char y;6. };7. int main()8. {9. struct p p1[] = {1, 92, 3, 94, 5, 96};10. struct p *ptr1 = p1;11. int x = (sizeof(p1) / 3);12. if (x == sizeof(int) + sizeof(char))13. printf("%d\n", ptr1->x);14. else15. printf("falsen");16. }

a)Compiletimeerror

b)1

c)Undefinedbehaviour

d)false

27. What is the output of this C code?

1. #include <stdio.h>2. struct p3. {4. int x;5. char y;6. };7. int main()8. {9. struct p p1[] = {1, 92, 3, 94, 5, 96};10. struct p *ptr1 = p1;11. int x = (sizeof(p1) / sizeof(ptr1));12. if (x == 1)13. printf("%d\n", ptr1->x);14. else15. printf("false\n");16. }

a)Compiletimeerror

b)1

Page 11: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

c)false

d)Undefinedbehaviour

28. What is the output of this C code?

1. #include <stdio.h>2. struct p3. {4. int x;5. char y;6. };7. typedef struct p* q*;8. int main()9. {10. struct p p1[] = {1, 92, 3, 94, 5, 96};11. q ptr1 = p1;12. printf("%d\n", ptr1->x);13. }

a)Compiletimeerror

b)1

c)Undefinedbehaviour

d)Segmentationfault

29. What is the output of this C code?

1. #include <stdio.h>2. struct p3. {4. int x;5. char y;6. };7. void foo(struct p* );8. int main()9. {10. typedef struct p* q;11. struct p p1[] = {1, 92, 3, 94, 5, 96};12. foo(p1);13. }14. void foo(struct p* p1)15. {16. q ptr1 = p1;17. printf("%d\n", ptr1->x);18. }

a)Compiletimeerror

b)1

Page 12: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

c)Segmentationfault

d) Undefined behaviour

30)what is the output of this C code?

1. #include <stdio.h>2. void main()3. {4. char *a[10] = {"hi", "hello", "how"};5. int i = 0, j = 0;6. a[0] = "hey";7. for (i = 0;i < 10; i++)8. printf("%s\n", a[i]);9. }

a) hi hello how Segmentation fault

b) hi hello how followed by 7 null values

c) hey hello how Segmentation fault

d) Depends on compiler

31. What is the output of this C code?

1. #include <stdio.h>2. void main()3. {4. char *a[10] = {"hi", "hello", "how"};5. printf("%d\n", sizeof(a));6. }

a)10

b)13

c)Runtimeerror

d) 40

32 What will be the output of following program ?123456789101112

#include <stdio.h>int main(){    static int var[5];    int count=0;         var[++count]=++count;    for(count=0;count<5;count++)        printf("%d ",var[count]);         return 0;}

Page 13: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

1. 0 1 0 0 02. 0 2 0 0 03. 0 0 2 0 04. 0 0 0 0 0

32) What will be the output of following program ?12345678

#include <stdio.h>int main(){    int MAX=10;    int array[MAX];    printf("size of array is = %d",sizeof(array);    return 0;}

1. size of array is = 202. size of array is = 403. size of array is = 44. Error

33) What will be the output of following program ?12345678

#include <stdio.h>#define MAX 10int main(){   int array[MAX]={1,2,3},tally;    for(tally=0;tally< sizeof(array)/sizeof(int);tally+=1)        printf("%d ",*(tally+array));    return 0;}

1. Error2. 1 3 4 5 6 7 8 9 10 113. 1 2 3 0 0 0 0 0 0 04. 0 0 0 0 0 0 0 0 0 0

34) What will be the output of following program ?1234567

#include <stdio.h>int main(){   static int x[]={'A','B','C','D','E'},tally;    for(tally=0;tally< sizeof(x)/sizeof(int) ; tally+=1)        printf("%c,%c,%c\n",*(x+tally)+1,x[tally]+1,*(tally+x)+1);    return 0;}

1. Error

Page 14: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?

2. A,A,AB,B,BC,C,CD,D,DE,E,E

3. B,B,BC,C,CD,D,DE,E,EF,F,F

4. E,E,ED,D,DC,C,CB,B,BA,A,A

35) What will be the output of following program ?123456

#include <stdio.h>int main(){   static int array[]={10,20,30,40,50};    printf("%d...%d",*array,*(array+3)* *array);    return 0;}

1. Error2. 10...403. 10...3004. 10....400

36) What will be the output of following program ?123456789101112

#include <stdio.h>int main(){   int a[5]={1,2,3,4,5},b[5]={10,20,30,40,50},tally;         for(tally=0;tally< 5;++tally)        *(a+tally)=*(tally+a)+ *(b+tally);         for(tally=0;tally< 5;tally++)        printf("%d ",*(a+tally));     return 0;}

1. 1 2 3 4 52. 10 20 30 40 503. 11 22 33 44 554. Error

Page 15: · Web viewa) alan alan alan turingb) alan alan turing turingc) alan turing alan turingd) Run time error18. What is the output of this C code?