ReviewEssays.com - Term Papers, Book Reports, Research Papers and College Essays
Search

C Programming Exam

Essay by   •  June 18, 2015  •  Exam  •  7,685 Words (31 Pages)  •  875 Views

Essay Preview: C Programming Exam

Report this essay
Page 1 of 31

(1)

void main(){

    char i;

    clrscr();

    for(i=120;i<=128;i++){

         printf("%d ",i);

    }

    getch();

}

Output: Infinite loop

(2)

void main(){

    int i;

    clrscr();

    for(i=0,i++,i<=5;i++,i<=2;i=0,i<=5,i+=3){

         printf("%d ",i);

    }

    getch();

}

Output: 2

(3)

void main(){

    int i=1;

    clrscr();

    for(;;){

         printf("%d ",i);

    }

    getch();

}

Output: Infinite loop

(4)

void main(){

    int i=2;

    clrscr();

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

         static int i;

         i=i+8;

    }

    printf("%d",i);

    getch();

}

Output: 4

(5)

extern int j;

void main(){

    int i=0;

    clrscr();

    for(i=0;i<=2;i+=1){

         int j=5;

         printf("%d ",j);

         j++;

    }

    getch();

}

int j=25;

Output: 5 5 5

(6)

extern int j;

void main(){

    int i=0;

    clrscr();

    for(i=0;i<=2;i+=1){

         int j=5;

         printf("%d ",j);

         j++;

    }

    getch();

}

int j=25;

1.

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

#include

void main(){

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

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

    printf("%d",sizeof('A'));

}

Choose all that apply:

(A)

4 2 1

[pic 1]

(B)

8 2 1 

[pic 2]

(C)

4 4 1

[pic 3]

(D)

8 4 1

[pic 4]

(E)

8 4 2

[pic 5]

Explanation:

By default data type of numeric constants is:

6.5 :  double

90000: long int

‘A’: char

In C size of data type varies from compiler to compiler.

In TURBO C 3.0 (16 bit compilers) size of:

double is 8 byte

Long int is 4 byte

Character constant is 2 byte   (size of char data type is one byte)

In TURBO C 4.5 or Linux GCC compilers (32 bit compilers) size of:

double is 8 byte

long int is 8 byte

Character constant is 2 byte   


2.

Consider on following declaring of enum.

(i)        enum  cricket {Gambhir,Smith,Sehwag}c;

(ii)      enum  cricket {Gambhir,Smith,Sehwag};

(iii)    enum   {Gambhir,Smith=-5,Sehwag}c;

(iv)      enum  c {Gambhir,Smith,Sehwag};

Choose correct one:

(A)

Only (i) is correct declaration

[pic 6]

(B)

Only (i) and (ii) is correct declaration

[pic 7]

(C)

Only (i) and (iii) are correct declaration

[pic 8]

(D)

Only (i),(ii) and are correct declaration

[pic 9]

(E)

All four are correct declaration

[pic 10]

Explanation:

Syntax of enum data type is:

enum  []{

    [=],

    …

} [,…]

Note:

[] : Represents optional .

<>: Represents any valid c identifier


3.

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

#include

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

}

Choose all that apply:

(A)

0 0

[pic 11]

(B)

65536 -10 

[pic 12]

(C)

0 65536 

[pic 13]

(D)

65536 0

[pic 14]

(E)

Compilation error

[pic 15]

...

...

Download as:   txt (44.4 Kb)   pdf (7 Mb)   docx (449.6 Kb)  
Continue for 30 more pages »
Only available on ReviewEssays.com