13
Q:

#define clrscr() 100

main()

{

clrscr();

printf( "%dn", clrscr() );

}

A) 100 B) 0
C) Compilation error D) Exception occurs

Answer:   A) 100



Explanation:

Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs.The input program to compiler looks like this :

main ()

{

100;

printf("%d\n",100);

}

Note: 100; is an executable statement but with no action. So it doesn't give any problem.

Subject: Programming
Q:

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

#include <stdio.h>
void main()

{
    int const SIZE = 5;
    int expr;
    double value[SIZE] = { 2.0, 4.0, 6.0, 8.0, 10.0 };
    expr=1|2|3|4;
    printf ( "%f", value[expr] );
}

A) 2.000000 B) 4.000000
C) 8.000000 D) Compilation error
 
Answer & Explanation Answer: D) Compilation error

Explanation:

Size of any array in c cannot be constantan variable.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

5 15931
Q:

What will be output of the following c program ?

#include

int main()

{

    int max-val=100;

    int min-val=10;

    int avg-val;

    avg-val =( max-val + min-val ) / 2;

    printf( "%d", avg-val );

    return 0;

}

A) 55 B) 105
C) 60 D) Compilation error
 
Answer & Explanation Answer: D) Compilation error

Explanation:

We cannot use special character – in the variable name.
Variable name can have only underscore.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

5 14799
Q:

What will output when you compile and run the following code?

#include <stdio.h>
struct student
{

int roll;
int cgpa;
int sgpa[8];

};

void main()
{

struct student s = { 12,8,7,2,5,9 };
int *ptr;
ptr = (int *)&s;
clrscr();
printf( "%d", *(ptr+3) );
getch();

}

A) 8 B) 7
C) 2 D) Compiler error
 
Answer & Explanation Answer: C) 2

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 13080
Q:

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

#include <stdio.h>
void main()

{
     switch(2)

      {
            case 1L:printf("No");
            case 2L:printf("%s","I");
              goto Love;
            case 3L:printf("Please");
            case 4L:Love:printf("Hi");
     }
}

A) I B) IPleaseHi
C) IHi D) Compilation error
 
Answer & Explanation Answer: C) IHi

Explanation:

It is possible to write label of goto statement in the case of switch case statement.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

3 11766
Q:

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

#include <stdio.h>
enum actor

{
    SeanPenn=5,
    AlPacino=-2,
    GaryOldman,
    EdNorton
};
void main()

{
     enum actor a=0;
     switch(a)

      {
         case SeanPenn:  printf("Kevin Spacey");
                         break;
         case AlPacino:  printf("Paul Giamatti");
                         break;
         case GaryOldman:printf("Donald Shuterland");
                         break;
         case EdNorton:  printf("Johnny Depp");
      } 
}

A) Kevin Spacey B) Paul Giamatti
C) Donald Shuterland D) Johnny Depp
 
Answer & Explanation Answer: D) Johnny Depp

Explanation:

Default value of enum constant
GaryOldman = -2 +1 = -1
And default value of enum constant
EdNorton = -1 + 1 = 0
Note: Case expression can be enum constant.

Report Error

View Answer Report Error Discuss

Filed Under: Programming

1 11533
Q:

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

#include <stdio.h>
void main()

{
    signed int a = -1;
    unsigned int b = -1u;
    if(a == b)
         printf( "The Lord of the Rings" );
    else
         printf( "American Beauty" );
}

A) The Lord of the Rings B) American Beauty
C) Compilation error: Cannot compare signed number with unsigned number D) Warning: Illegal operation
 
Answer & Explanation Answer: A) The Lord of the Rings

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Programming

11 18969
Q:

What will be output of following c code?

void main()
{
struct india
{
char c;
float d;
};
struct world
{
int a[3];
char b;
struct india orissa;
};
struct world st ={{1,2,3},'P','q',1.4};
clrscr();
printf("%dt%ct%ct%f",st.a[1],st.b,st.orissa.c,st.orissa.d);
getch();
}

Answer

Output: 2 p q 1.400000

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

1 2271
Q:

What will be output of following c code?

void main()
{
struct bitfield
{
unsigned a:5;
unsigned c:5;
unsigned b:6;

}bit;
char *p;
struct bitfield *ptr,bit1={1,3,3};
p=&bit1;
p++;
clrscr();
printf("%d",*p);
getch();
}

Answer

Output: 12

Explanation:
Binary value of a=1 is 00001 (in 5 bit)
Binary value of b=3 is 00011 (in 5 bit)
Binary value of c=3 is 000011 (in 6 bit)

In memory it is represented as:
Let address of bit1 is 500 which initialize to char pointer p. Since can is one byte data type so p++ will be 501. *p means content of memory location 501 which is (00001100) and its binary equivalent is 12. Hence output is 12.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

0 3000