C MCQ

MCQ

What is the output of the following code?

int a = 5, b = 10;
a = a ^ b;
b = a ^ b;
a = a ^ b;
 printf("%d %d", a, b);
  • 5 10
  • 10 5
  • 0 10
  • 10 0
View Answer

10 5

What is the correct syntax for a multi-line comment in C?

  • /* This is a comment */
  • // This is a comment //
  • { This is a comment }
  • / This is a comment //
View Answer

/* This is a comment */

Which operator has the highest precedence in C?

  • ++ (postfix)
  • *
  • ==
  • &&
View Answer

++ (postfix)

What is the output of the following code?

int x = 5;
printf("%d", x++);
  • 5
  • 6
  • 4
  • Error
View Answer

5

What is the output of the following code?

int i = 0;
for (i = 0; i < 5; i++) {
printf("%d ", i);
if (i == 3) {
break;
}
}
  • 0 1 2 3
  • 0 1 2 3 4
  • 0 1 2 3 4 5
  • None of the above
View Answer

0 1 2 3 

What is the output of the following code?

int i = 0;
while (i < 5) {
printf("%d ", i);
i++;
}
  • 0 1 2 3
  • 0 1 2 3 4
  • 0 1 2 3 4 5
  • None of the above
View Answer

0 1 2 3 4

What is the output of the following code?

int i = 0;
do 
{
    printf("%d ", i);
    i++;
} while (i < 5);
  • 0 1 2 3
  • 0 1 2 3 4
  • 0 1 2 3 4 5
  • None of the above
View Answer

0 1 2 3 4

What is the output of the following code?

int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printf("%d", arr[2][1]);
  • 1
  • 5
  • 8
  • 6
View Answer

8

What is the output of the following code?

char str[] = "Hello World";
printf("%s", str);
  • Hello World
  • H
  • Error
  • None of the above
View Answer

Hello World

What is the output of the following code?

int a = 5;
int b = 10;
swap(a, b);
printf("%d %d", a, b);
void swap(int x, int y)
 {
    int temp = x;
    x = y;
    y = temp;
}
  • 5 10
  • 10 5
  • Error
  • None of the above
View Answer

5 10

What is the output of the following code?

#include<stdio.h>
int main() 
{
  char c = 'A';
  printf("%d %c", c, c);
  return 0;
}
  • 65 A
  • A 65
  • Error
  • None of the above
View Answer

65 A

What is the output of this C code?

#include<stdio.h>
int main()
 {
     char c = 'A';
     printf("%d %c", c+32, c+32);
     return 0;
}
  • 65 a
  • 97 a
  • Error
  • None of the above
View Answer

97 a

What is the output of this C code?

#include<stdio.h>
int main() {
char str[] = "hello";
printf("%d", sizeof(str));
return 0;
}
  • 5
  • 6
  • 7
  • Error
View Answer

6

What is the output of this C code?

#include<stdio.h>
int main() 
{
    char str[] = "hello";
    printf("%d", strlen(str));
    return 0;
}
  • 5
  • 6
  • 7
  • Error
View Answer

5

What is the output of this C code?

#include<stdio.h>
int main() 
{
     char str1[] = "hello";
     char str2[] = "world";
     strcpy(str1, str2);
     printf("%s", str1);
     return 0;
}
  • hello
  • world
  • horld
  • Error
View Answer

world

What is the output of this C code?

#include<stdio.h>
int main() {
char str1[] = "hello";
char str2[] = "world";
int res = strcmp(str1, str2);
printf("%d", res);
return 0;
}
  • 0
  • -1
  • 1
  • Error
View Answer

-1

What is the output of this C code?

#include<stdio.h>
int main() 
{
    char str[] = "hello";
    printf("%s", str+2);
    return 0;
}
  • hello
  • lo
  • llo
  • Error
View Answer

llo

What is the output of this C code?

#include<stdio.h>
#define square(x) x*x
void main()
{
    
    int i;
    i=(64/square(4));
    printf("%d",i);
}
  • 64
  • 16
  • 4
  • Error
View Answer

64

What is the output of this C code?

#include<stdio.h>
int main()
{
    int x=5, y=1;
    int z=(y++)? 2: y==1 && x||y;
   printf("%d\n",--z);
    return 0;
}
  • 0
  • 1
  • 2
  • 3
View Answer

1

What is the output of this C code?

#include<stdio.h>
int main()
{
     int a=1, b=3;
     a+=b-=a;
     printf("%d,%d",a,b);
}
  • 3,2
  • 4,2
  • 4,-1
  • 2,3
View Answer

3,2

What is the output of this C code?

#include<stdio.h>
int main()
{
    enum choice
   {
       Tea=-1,Coffee,Milk
   };
   int x=Tea + Milk;
   switch (x){
   case Tea:
   printf("Choice is Tea");
   break;
   case Coffee:
   printf("Choice is Coffee");
   break;
  case Milk:
   printf("Choice is Milk");
  break;
  default:
  printf("Not in list");
  break;
}
return 0;
}
  • Choice is Tea
  • Choice is Coffee
  • Choice is Milk
  • Not in list
View Answer

Choice is Coffee

What is the output of this C code?

#include<stdio.h>
main()
{
   char ch;
   ch = 128;
   printf("%d\n",ch);
   return 0;
}
  • 128
  • -128
  • 0
  • Garbage Value
View Answer

-128

What is the output of this C code?

#include<stdio.h>
int main()
{
    int a = 10, b = 5, c = 3;
    b != !a;
    c = !!a;
    printf("%d\t%d", b, c);
}
  • 5 1
  • 10 10
  • 1 10
  • 1 1
View Answer

5 1

What is the output of this C code?

#include<stdio.h>
main()
{
int i=3;
int j;
j=sizeof(++i + ++i);
printf("i=%d j=%d", i, j);
}
  • i=4 j=2
  • i=3 j=2
  • i=3 j=4
  • c=5 d=5
View Answer

i=3 j=4

What is the output of this C code?

#include<stdio.h>
int main()
{
   int a, b, c, d;
   a=3;
   b=5;
   c=a,b;
  d=(a,b);
  printf("c=%d",c);
  printf("d=%d",d);
}
  • c=3 d=3
  • c=5 d=3
  • c=3 d=5
  • c=5 d=5
View Answer

c=3 d=5

What is the output of this C code?

  int  main()
    {
        if (~0 == 1)
             printf("EQUAL");
        else
             printf("NOT EQUAL");
       return 0;
    }
  • EQUAL
  • NOT EQUAL
  • Compile time error
  • Undefined
View Answer

NOT EQUAL

What is the output of this C code?

#include<stdio.h>
main()
{
   int i=0;
   for(i=0;i<20;i++)
   {
       switch(i)
       {
            case 0:i+=5;
            case 1:i+=2;
            case 5:i+=5;
            default:i+=4;
            break;
      }
      printf("%d, ",i);
  }
  return 0;
}

  • 0,5,9,13,17,
  • 5,9,13,17,
  • 12,17,22,
  • 16,21,
View Answer

16,21,

What is the output of this C code?

#include<stdio.h>
int main ()
{
   int i=5;
   while(i--)
   {
        int i=11;
        i--;
        printf ("%d ",i);
   }
   return 0;
}
  • 10 10 10 10 10
  • 5 4 3 2 1
  • 10 9 8 7 6
  • Infinite loop
View Answer

10 10 10 10 10

What is the output of this C code?

#include<stdio.h>
#include<setjmp.h>
static jmp_buf buf;
int main()
{
      volatile int b;
       b=3;
       if (setjmp(buf)!=0)
       {
            printf("%d", b);
            return(0);
       }
       b=5;
       longjmp(buf,1);
}
  • 3
  • 5
  • 0
  • 1
View Answer

5

Which of the following statement is an infinite loop?

(i) while (1) {}
(ii) while (15) {}
(iii) while (“infinite”) {}
(iv) for (;;) {}
  • Expression (i)
  • Expression (ii)
  • Expression (iii)
  • All the above expressions.
View Answer

All the above expressions.

Which one of the following correct with respect to size of the datatypes?

  • char > int > float
  • All the statements
  • char < int < double
  • double > char > int
View Answer

char < int < double

Statement 1: Extern variable can be declared multiple times but can be defined only once.
Statement 2: usage of ‘&’ operator on the register variable is restricted.?

  • Statement 1 is true, statement 2 is false.
  • Statement 1 is false, statement 2 is true
  • Both statements 1 & 2 are true.
  • Both statements 1 & 2 are false.
View Answer

Both statements 1 & 2 are true.

What is the output of this C code?

#include <stdio.h>
#define y *
int main()
{
      int x=5,z=3;
      printf("%d", x y z);
      return 0;
}
  • 5 3
  • 5 y 3
  • 1 5
  • 0
View Answer

1 5

What is the output of this C code?

#include <stdio.h>
int main()
{
       static int num[3]={[0]=5,[2]=7};
       printf("%d ",num[1]);
       return 0;
}
  • 0
  • 5
  • 7
  • Garbage Value
View Answer

0

What is the output of this C code?

#include <stdio.h>
main()
{
    #ifndef hello
    printf("hello");
    #endif
    printf("world");

}
  • hello
  • world
  • helloworld
  • null
View Answer

helloworld

What is the output of this C code?

#include <stdio.h>
main()
{
       int A[] ={2,4,6,8,10};
      1[A]=A[(&A[4]-&A[0])];
       printf("%d",*(1+A));
}
  • 2
  • 4
  • 8
  • 10
View Answer

10

What is the output of this C code?

#include <stdio.h>
main()
{
    #define a 5
    printf("%d",a++);
}
  • 5
  • 6
  • 0
  • Error
View Answer

Error

What is the output of this C code?

#include <stdio.h>
main()
{
       int A[10] ={2,4,6,8,10,12,14,16};
       printf("%d",(A+2)[3]);
}
  • 6
  • 8
  • 12
  • 14
View Answer

12

What is the output of this C code?

#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%s\n",argv[0]);
return 0;
}
  • 0
  • 1
  • Compilation error
  • Executable file name.
View Answer

Executable file name.

What is the output of this C code?

#include <stdio.h>
int main(int argc, char *argv[])
{
       if (argv[argc])
              printf("Hello");
              printf("World");
       return 0;
}
  • Hello
  • World
  • HelloWorld
  • Null
View Answer

World

What is the output of this C code?

#include <stdio.h>
int main()
{
    union a
    {
          char ch[2];
          char rh[2];
     };
     union a key;
     key.ch[0]=5;
     key.ch[1]=7;
     printf("key.rh[1] = %d ",key.rh[1]);
     return 0;
}
  • key.rh[1] = 5
  • key.rh[1] = 7
  • key.rh[1] = 0
  • key.rh[1] = Garbage Value.
View Answer

key.rh[1] = 7

What is the output of this C code?

#include <stdio.h>
int main()
{
     union a
     {
          short i;
          char j[2];
     };
     union a key;
     key.i=514;

     printf("%d, ",key.j[0]);
     printf("%d ",key.j[1]);
     return 0;
}
  • 0, 0
  • 2, 0
  • 0, 2
  • 2, 2
View Answer

2, 2

What is the output of this C code?

#include <stdio.h>
int main()
{
char x;
x='A';
printf("%d",x);
return 0;
}
  • 62
  • 65
  • 71
  • 96
View Answer

65

Which of the following expression will swap the values in the variable a, b?

  • a=a-b; b=a+b; a=b-a;
  • a=a+b; b=a-b; a=a-b;
  • a=a*b; b=a/b; a=a/b;
  • All the above expressions.
View Answer

All the above expressions.

What is the output of this C code?

#include <stdio.h>
#include <string.h>
int main ()
{
      int i = 5;
     switch(i)
    {
     static int i;
     case 3:
        i=i+i;
     case 4:
        i=i+i;
      case 5:
        i=i+i;
     default:
        i=i+i;
        printf("%d ",i);
   }
  printf("%d ",i);
  return 0;
}
  • 36 5
  • 0 5
  • 18 18
  • 5 5
View Answer

0 5

What is the output of this C code?

#include <stdio.h>
main ()
{
  int a=2, b=3, c=5;
  a<<=c>b>a^a<c<b;
  printf("%d",a);
}
  • 4
  • 2
  • 1
  • 0
View Answer

4

What is the output of this C code?

#include <stdio.h>
main ()
{
      int a=2;
      if(++a^++a&&(a^a)||++a)
      printf("%d",a);
}
  • 4
  • 5
  • 6
  • 3
View Answer

5

What is the output of this C code?

#include <stdio.h>
main ()
{
    while(1)
    {
          int i = 0;
          while(i<10)
         {
               ++i;
               for(;;)
              {
                      if(++i<5)
                     continue;
                     break;
              }
       }
       printf("%d",i);
       break;
    }
}
  • 10
  • 11
  • 9
  • program run infinite.
View Answer

11

What is the output of this C code?

#include <stdio.h>
int main ()
{
    char a[]="abcde";
    char* p=a;
    p++;
    p++;
    p[2]='z';
    printf("%s",p);
    return 0;
}
  • abcde
  • abzde
  • zde
  • cdz
View Answer

cdz

What is the output of this C code?

#include <stdio.h>
int main()
{
    int x=15,y=3;
    printf("%d\n", x+(~y)+1);
    return 0;
}
  • 5
  • 12
  • 18
  • 45
View Answer

12

What is the output of this statement?

printf("%d",3^2?~0+1?5:1:12);
  • 5
  • 1
  • 12
  • 0
View Answer

1

What is the output of this C code?

#include <stdio.h>
int main()
{
    char a[] = "%d";
    int b=12;
    a[1] = 88;
    printf(a,b);
    return 0;
}
  • A
  • B
  • C
  • D
View Answer

C

What is the output of this C code?

#include <stdio.h>
int main()
{
    char a=128;
    char b=a-1;
    printf("%d",a-b);
    return 0;
}
  • 0
  • 1
  • 255
  • -255
View Answer

-255

What is the output of this C code?

#include <stdio.h>
void func()
 {
      int a[] = {1, 2, 3, 4, 5};
      int sum = 0;
      for(int i = 0; i < 5; i++) 
      {
            if(i % 2 == 0)
                  sum += *(a + i);
            else
                  sum -= *(a + i);
      }
      printf("%d", sum);
}
int main() 
{
    func();
    return 0;
}
  • 3
  • 6
  • 9
  • 15
View Answer

3

What is the output of the program

#include <stdio.h>
int main()
{
    int i = 3;
    printf("%d", (++i)++);
    return 0;
}
  • 3
  • 4
  • 5
  • Compile Time Error
View Answer

Compile Time Error

What is the output of the program

#include <stdio.h>
#if X == 3
    #define Y 3
#else
    #define Y 5
#endif
 
int main()
{
    printf("%d", Y);
    return 0;
}
  • 3
  • 5
  • 1
  • Compile Time Error
View Answer

5

Which of the following is true about return type of functions in C?

  • Functions can return any type
  • Functions can return any type except array and functions
  • Functions can return any type except array, functions and union
  • Functions can return any type except array, functions, function pointer and union
View Answer

Functions can return any type except array and functions

Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is

struct  stu
{ 
    short s[5];
    union 
    { 
         float y; 
         long z; 
    }u; 
} t;
  • 22
  • 14
  • 18
  • 10
View Answer

18

Which of the following is not a storage class specifier in C?

  • auto
  • register
  • Extern
  • Volatile
View Answer

Volatile

Which of the following is not a logical operator?

  • &&
  • ||
  • |
  • !
View Answer

|

Which file is generated after pre-processing of a C program?

  • .p
  • .i
  • .o
  • .m
View Answer

.i

What does the following C statement mean?

scanf("%4s", str);
  • Reads exactly 4 letters from console
  • Reads maximum of 4 letters from console
  • Compile error
  • Reads a string str in multiples of 4
View Answer

Reads maximum of 4 letters from console

Assume that a character takes 1 byte. Output of following program?

#include <stdio.h>
int main()
{
       char str[20] = "SkillLyncQuiz";
       printf ("%d", sizeof(str));
       return 0;
}
  • 1
  • 20
  • 21 to store \0
  • 25
View Answer

20

What is the output of the following Code?

#include <stdio.h> 
int main()
{
    unsigned int i = 65000;
    while (i++ != 0);
    printf("%d", i);
    return 0;
}
  • 65535
  • 1
  • -65534
  • infinite loop
View Answer

1

Which of the following is true for variable names in C?

  • They can contain alphanumeric characters as well as special characters
  • It is not an error to declare a variable to be one of the keywords(like goto, static)
  • Variable names cannot start with a digit
  • Variable can be of any length
View Answer

Variable names cannot start with a digit

Which one of the following is a loop construct that will always be executed once?

  • while
  • for
  • do ..while
  • switch
View Answer

do ..while

A global variable is declared __________.

  • outside the function
  • Inside of the function
  • With the function
  • Anywhere in the program
View Answer

outside the function

What is the result after execution of the following code if a is 10, b is 5, and c is 10?

#include<stdio.h> 
int main() 
{ 
    int a=10,b=5,c=10; 
    if ((a > b) && (a <= c))           
          a = a + 1;   
    else          
          c = c+1; 
    printf("%d %d",a,c); 
    return 0;
} 
  • a = 10, c = 11
  • a = 11, c = 10
  • a = 11, c = 11
  • a = 10, c = 10
View Answer

a = 11, c = 10

What is an example of iteration in C?

  • while
  • for
  • do ..while
  • All of the Above
View Answer

All of the Above

In the C language, the constant is defined _______. ?

  • Before main()
  • After main()
  • Anywhere, but starting on a new line
  • None of the these.
View Answer

Anywhere, but starting on a new line

What is the output of this C code?

#include <stdio.h>
int main() 
{ 
   int j = 1, num1 = 4;   
   while (++j <= 10)   
   {     
       num1++;  
   }   
   printf("%d",num1); 
   return 0;
} 
  • 11
  • 12
  • 13
  • 14
View Answer

13

A machine in which the least significant bit is stored in the smallest address is __________

  • Big endian machine
  • Little endian machine
  • Short endian machine
  • None of the above
View Answer

All the above

What is the output of this C code?

#include <stdio.h>
#define a 5 
Int main() 
{ 
    printf("%d",a++); 
   return 0; 
} 
  • 5
  • 6
  • error
  • None of the above
View Answer

error

What is the output of this C code?

#include <stdio.h>
int main() 
{ 
              int h[4]={5,6,7,8}; 
              int *a=h; 
              printf("%d ",*a); 
} 
  • 5
  • 6
  • error
  • None of the above
View Answer

5

Which of the following expression will swap the values in the variable a, b?

  • a=a-b; b=a+b; a=b-a;
  • a=a+b; b=a-b; a=a-b;
  • a=a*b; b=a/b; a=a/b;
  • All the above
View Answer

All the above

What is the output of the following Code?

#include <stdio.h>
int main() 
{ 
      int i=4,z=12; 
      if(i=5 || z>50) 
           printf("hello"); 
     else 
           printf("hi"); 
} 
  • hello
  • hi
  • hello hi
  • None of the above
View Answer

hello

What is the output of the following Code?

#include <stdio.h>
int main() 
{ 
      int k,num=30; 
      k=(num>5?(num<=10?100:200):500); 
      printf("%d %d",num,k); 
      return 0;
}
  • 30,100
  • 200,200
  • 30,200
  • None of the above
View Answer

30,200

What is the output of the following Code?

int i=2; 
if(i) 
    printf("1"); 
else if(i==2) 
    printf("2"); 
else 
   printf("others"); 
  • 1
  • 2
  • other
  • None of the above
View Answer

1

A “switch” statement is used to

  • Switch between functions in a program
  • Switch from one variable to another variable
  • To choose from multiple possibilities which may arise due to different values of a single variable
  • All of above
View Answer

To choose from multiple possibilities which may arise due to different values of a single variable

What is the output of the following Code?

int a=0; 
if(a=0) 
     printf ("a is zero"); 
else  
     printf ("a is not zero"); 
  • a is zero
  • a is not zero
  • error
  • None of the above
View Answer

a is not zero

What is the output of the following Code?

main() 
{ 
    int i=1; 
    switch(i) 
    { 
        default:printf("zero"); 
        case 1: printf("one"); 
        break; 
        case 2:printf("two"); 
        break; 
        case 3: printf("three"); 
        break; 
    } 
} 
  • zero
  • one
  • two
  • three
View Answer

one

What is the output of the following Code?

int main() 
{ 
    int i=6; 
    switch(i) 
    { 
        default:printf("zero"); 
        case 1: printf("one"); 
        break; 
        case 2:printf("two"); 
        break; 
        case 3: printf("three"); 
        break; 
    } 
    return 0;
} 
  • zero
  • one
  • both the above statements
  • three
View Answer

both the above statements

What is the output of the following Code?

 #include <stdio.h>
       int main() 
{ 
      int n = 0; 
      if (n == 1) 
           if (n >= 0) 
                  printf("True...\n"); 
           else 
                 printf("False...\n"); 
} 
  • True
  • false
  • error
  • prints nothing
View Answer

prints nothing

Which of the following cannot be checked in a switch – case statement?

  • int
  • float
  • char
  • enum
View Answer

float

What is the output of the following Code?

 #include <stdio.h>
        int main() 
    { 
        float n = 1.2; 
        switch (n) 
        { 
        case 1.0: 
            printf("Option: First\n"); 
            break; 
        default: 
            printf("Option: Default\n"); 
        } 
    } 
  • Default
  • Run time error
  • Compile time error
  • First
View Answer

Compile time error

What is the output of the following Code?

 #include <stdio.h>
       int  main() 
    { 
        int p = 6; 
        if (p < 2); 
            printf("Hey..."); 
        return 0;
  
    } 
  • Hey
  • Run time error
  • Compile time error
  • prints nothing
View Answer

Hey

What is the output of the following Code?

 #include <stdio.h>
    int main() 
    { 
        int n; 
       n=1; 
        switch (n, n + 1) 
        { 
            case 1: 
                        printf("1\n"); 
                        break; 
           case 2: 
                        printf("2"); 
                        break; 
        } 
     return 0;
    } 
  • 1
  • Run time error
  • Compile time error
  • 2
View Answer

2

What is the output of the following Code?

 #include <stdio.h>
   int main() 
    { 
        int n = 5; 
        if (n > 1) 
            printf("Inside if block executed...\n"); 
        else if (n == 5) 
            printf("Inside else if block executed...\n"); 
        return 0;
    } 
  • Inside if block executed
  • Inside else if block executed
  • None of the statement
  • 5
View Answer

5

What is the output of the following Code?

 #include <stdio.h>
 #define max(p) p 
   int main() 
    { 
      int n = 1; 
      switch (n) 
    { 
    case max(2): 
    case max(1): 
   break; 
        } 
    }
  • 1
  • 2
  • Right
  • Wrong
View Answer

Wrong

What is the result of 64&&32?

  • 31-
  • 64
  • 1
  • 0
View Answer

1

What is the value of a?

int a = 10 + 4.867; 
  • 10
  • 4.867
  • 14.867
  • 14
View Answer

14

What number will z in the sample code given below?

int z, x = 5, y = -10, a = 4, b = 2; 
z = x++ - --y*b/a; 
  • 5
  • 6
  • 9
  • 10
View Answer

10

Given b = 110 and c = 20, what is the value of ‘a’ ,b,c after execution of the expression a = b = c*=5?

  • 110,100,100
  • 100,100,100
  • 100,110,100
  • 100,100,100
View Answer

100,100,100

Determine Output:

int main() 
{ 
      int i = 0, j = 1, k = 2, m; 
      m = i++ || j++ || k++; 
      printf("%d %d %d %d", m, i, j, k);
      return 0; 
} 
  • 3 1 2 2
  • 3 1 1 2
  • 1 1 2 2
  • 1 1 2 1
View Answer

1 1 2 2

Determine Output:

int  main()  
{ 
      int c = - ( -2); 
      printf("c = %d", c); 
      return 0;
} 
  • 0
  • -2
  • 2
  • Garbage value
View Answer

2

Determine Output:

int main() 
{ 
      int i = 10; 
      i = !i>14; 
     printf("i = %d", i); 
     return 0;
} 
  • 0
  • 10
  • 1
  • Garbage value
View Answer

0

What is the value of k?

int a=3,b=2,x=5,y=4; 
int k=5*b*b*x-3*a*y*y-8*b*b*x+10*a*y; 
  • 45
  • -125
  • 82
  • -84
View Answer

-84

Evaluate the expression

2*3/4+4/4+8-2+5/8 
  • 45
  • 12
  • 8
  • -16
View Answer

8

What is the output of the following Code?

int x=4,y,z; 
y=--x; 
z=x--; 
printf("%d\t%d\t%d",x,y,z); 
  • 1 2 3
  • 1 1 3
  • 2 3 3
  • 1 1 1
View Answer

2 3 3

What is the output of the following Code?

int main() 
{ 
       int x=4,y=0,z=0; 
       y=x-- -y; 
       printf("%d\t%d\t%d",x++,--y,z); 
       return 0;
}
  • 1 2 3
  • 1 1 3
  • 3 3 0
  • 1 1 1
View Answer

3 3 0

Evaluate x=2%2+2*2-2/2

  • 45
  • 12
  • 8
  • 3
View Answer

3

Evaluate x=7+3*6/2-1

  • 45
  • 12
  • 15
  • 3
View Answer

15

Dynamically allocated memories are allocated in which part of a memory?

  • Heap
  • Stack
  • RAM
  • Register
View Answer

Heap

What is the correct syntax to declare a function foo() which receives an array of structure in function()?

  • None
  • void foo(struct var)
  • void foo(struct *var[])
  • void foo(struct *var);
View Answer

void foo(struct *var);

The size of a union is determined by the size of the __________

  • First member in the union
  • Last member in the union
  • Sum of the sizes of all members
  • Biggest member in the union
View Answer

Biggest member in the union

A user defined data type, which is used to assign names to integral constants is called ___________

  • union
  • array
  • enum
  • structure
View Answer

Stack

Local variables are stored in an area called ___________

  • Stack
  • RAM
  • ROM
  • Heap
View Answer

enum

What is the return type of the fopen() function in C?

  • Stack
  • RAM
  • pointer variable
  • Pointer to FILE object
View Answer

pointer variable

What is the output of the program?

#include <stdio.h> 
int main() 
{ 
      int x=4,y=5; 
      printf("%d",x||y?x:y); 
} 

  • 45
  • 12
  • 8
  • 4
View Answer

4

What is the output of the program?

#include <stdio.h> 
int x; 
int main() 
{ 
     printf("hello"); 
     while(x) 
          printf("world"); 
     return 0;
} 
  • hello
  • hello world
  • hello. Infinite times world priniting
  • world..world…
View Answer

hello

What is the output of the program?

#include <stdio.h> 
  int main() 
{ 
      int x=5,y=-6; 
      printf("%d",(x&&y));
      return 0;  
} 
  • 0
  • 1
  • 6
  • 5
View Answer

1

What is the output of the program?

#include <stdio.h> 
 int main() 
 { 
        int a = 3, b = 5;          
        int t = a;          
        a = b;          
        b = t;          
       printf("%d %d", a, b);         
       return 0; 
} 
  • 0 5
  • 0 3
  • 3 5
  • 5 3
View Answer

5 3

What is the output of the program?

#include <stdio.h> 
int main() 
{ 
    static int var=5; 
    printf("%d",var--); 
    if(var) 
    main(); 
    return 0;
} 
  • compile error
  • run time error
  • 5 4 3 2 1
  • 4 3 2 1 0
View Answer

5 4 3 2 1

What is the output of the program?

#include <stdio.h> 
int main() 
{ 
     printf("%x",-1<<4); 
     return 0;
} 
  • 08
  • 80
  • f0f0 fff8
  • ffff fff0
View Answer

 ffff fff0

What is the output of the following Code?

#include <stdio.h> 
int main() 
{ 
    int i=5; 
    printf("%d%d%d%d%d",i++,i--,++i,--i,i); 
    return 0;
} 
  • 45323
  • 43544
  • 44555
  • 45555
View Answer

45555

What is the output of the following Code?

#include <stdio.h> 
int main()
{
    int i=200,j=300;
    printf("%d %d");
    return 0;
}
  • 200 300
  • Garbage values
  • Run time error
  • syntax error
View Answer

Garbage values

How to declare double pointer in c

  • int *val
  • Int &&val
  • Int **val
  • Int &val
View Answer

Int **val

What is the output of the following code?

int a = 5, b = 10;
printf("%d", a + b);
  • 10
  • 15
  • 20
  • Error
View Answer

15

What is the output of the following code?

int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d", *ptr);
  • 1
  • 2
  • Error
  • None of the above
View Answer

1

What is the output of the following code?

int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d", *(ptr+2));
  • 1
  • 2
  • 3
  • 4
View Answer

3

What is the output of the following code?

int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
ptr += 2;
printf("%d", *ptr);
  • 1
  • 2
  • 3
  • 4
View Answer

3

What is the output of the following code?

int arr[] = {1, 2, 3, 4, 5};
int *ptr = &arr[2];
printf("%d", *ptr);
  • 1
  • 2
  • 3
  • 4
View Answer

3

What is the output of the following code?

int arr[] = {1, 2, 3, 4, 5};
int *ptr = &arr[2];
*ptr = 10;
printf("%d %d", arr[2], arr[3]);
  • 3 4
  • 10 4
  • 3 10
  • 10 5
View Answer

10 4

What is the output of the following code?

int a = 5;
int *p = &a;
*p = 10;
printf("%d %d", a, *p);
  • 5 5
  • 5 10
  • 10 10
  • Error
View Answer

10 10

What is the output of the following code?

int a = 5;
int b = 10;
swap(&a, &b);
printf("%d %d", a, b);
void swap(int *x, int *y) 
{
     int temp = *x;
     *x = *y;
     *y = temp;
}
  • 5 10
  • 10 5
  • Error
  • None of the above
View Answer

10 5

What is the output of the following code?

#include <stdio.h>
int main()
 {
        int a = 5, b = 10;
        int *p1 = &a, *p2 = &b;
        int *temp;
        temp = p1;
        p1 = p2;
        p2 = temp;A) 5 10
        printf("%d %d", *p1, *p2);
        return 0;
}
  • 5 10
  • 10 5
  • Error
  • None of the above
View Answer

10 5

What is the output of the following code?

#include <stdio.h>
int main
 {
       int a = 5;
       int *p = &a;
       printf("%d %u", a, p);
       return 0;
}
  • 5 random value
  • 5 address of a
  • Error
  • None of the above
View Answer

5 address of a

What is the output of the following code?

#include <stdio.h>
int main() 
{
      int arr[3] = {1, 2, 3};
      int *p = arr;
      printf("%d %d", *p, *(p+1));
      return 0;
}
  • 1 2
  • 2 3
  • Error
  • None of the above
View Answer

1 2

What is the output of the following code?

#include <stdio.h>
int main() 
{
      int arr[3] = {1, 2, 3};
      int *p = arr;
      p++;
      printf("%d", *p);
      return 0;
}
  • 1
  • 2
  • 3
  • Error
View Answer

2

What is the output of the following code?

#include <stdio.h>
int main()
 {
        int arr[3] = {1, 2, 3};
        int *p = arr;
       *p = 10;
        printf("%d %d %d", *p, *(p+1), *(p+2));
        return 0;
}
  • 10 2 3
  • 1 10 3
  • 1 2 10
  • Error
View Answer

10 2 3

What is the output of the following code?

#include <stdio.h>
int main()
 {
      int arr[3] = {1, 2, 3};
      int *p = arr;
     *(p+1) = 10;
      printf("%d %d %d", *p, *(p+1), *(p+2));
     return 0;
}
  • 1 10 3
  • 1 2 3
  • Error
  • None of the above
View Answer

1 10 3

What is the output of the following code?

#include <stdio.h>
int main() 
{
       int arr[3] = {1, 2, 3};
       int *p = arr+2;
       printf("%d", *p);
       return 0;
}
  • 1
  • 2
  • 3
  • Error
View Answer

3

What is the output of the following code?

#include <stdio.h>
int main() 
{
      int arr[3] = {1, 2, 3};
      int *p = arr+2;
      p--;
      printf("%d", *p);
      return 0;
}
  • 1
  • 2
  • 3
  • Error
View Answer

2

What is the output of the following code?

#include <stdio.h>
int main() 
{
      int arr[3][2] = {{1, 2}, {3, 4}, {5, 6}};
      printf("%d", *(arr[1]+1));
      return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

4

What is the output of the following code?

#include <stdio.h>
int main() 
{
         int arr[3][2] = {{1, 2}, {3, 4}, {5, 6}};
         printf("%d", ((arr+2)+1));
         return 0;
}
  • 1
  • 2
  • 5
  • 6
View Answer

6

What is the output of the following code?

#include <stdio.h>
int main() 
{
         int arr[3][2] = {{1, 2}, {3, 4}, {5, 6}};
         printf("%d", (*(arr+1))[1]);
         return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

4

What is the output of the following code?

#include <stdio.h>
int main() 
{
         int arr[3][2] = {{1, 2}, {3, 4}, {5, 6}};
         printf("%d", (*(arr+2))[0]);
         return 0;
}
  • 1
  • 3
  • 5
  • Error
View Answer

5

What is the output of the following code?

#include <stdio.h>
int main() 
{
             int arr[3][2] = {{1, 2}, {3, 4}, {5, 6}};
             int (*p)[2];
             p = arr+1;
             printf("%d", ((p+1)+1));
             return 0;
}
  • 1
  • 2
  • 4
  • 6
View Answer

4

What is the output of the following code?

#include <stdio.h>
int main() 
{
      int arr[] = {10, 20, 30};
      int *p;
     p = arr+1;
     printf("%d", *p);
     return 0;
}
  • 10
  • 20
  • 30
  • Error
View Answer

20

What is the output of the following code?

#include <stdio.h>
int main()
 {
       int arr[] = {10, 20, 30};
       printf("%d", *(arr+2));
       return 0;
}
  • 10
  • 20
  • 30
  • Error
View Answer

30

What is the output of the following code?

#include <stdio.h>
int main()
 {
      int arr[] = {10, 20, 30};
      printf("%d", *(arr+3));
      return 0;
}
  • 10
  • 20
  • 30
  • Error
View Answer

Error

What is the output of the following code?

#include <stdio.h>
int main()
{
      int h[4]={5,6,7,8};
      int *a=h;
      printf("%d ",*a);
     return 0;
}
  • 4
  • 5
  • 0
  • Garbage Value
View Answer

5

What is the output of the following code?

#include <stdio.h>
int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
ptr++;
printf("%d", *ptr);
  • 1
  • 2
  • Error
  • None of the above
View Answer

2

What is the output of the following code?

#include <stdio.h>
int main()
{
      int arr[] = {10, 20, 30};
      int *p = arr;
      printf("%d", p[1]);
      return 0;
}
  • 10
  • 20
  • 30
  • Error
View Answer

20

What is the output of the following code?

#include <stdio.h>
  int main() 
{
      int arr[] = {10, 20, 30};
      int *p = arr+2;
      printf("%d", p[-1]);
      return 0;
}
  • 10
  • 20
  • 30
  • Error
View Answer

20

What is the output of the following code?

#include <stdio.h>
  int main() 
{
          int arr[] = {10, 20, 30};
          int *p = arr+1;
          printf("%d", ++*p);
          return 0;
}
  • 21
  • 22
  • 23
  • Error
View Answer

21

What is the correct syntax to declare a function foo() which receives an array of structure ?

  • void foo(struct *var);
  • void foo(struct *var[]);
  • void foo(struct var)
  • None
View Answer

void foo(struct *var);

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
      char str[] = "hello";
      printf("%c", *(str+3));
      return 0;
}
  • h
  • e
  • l
  • o
View Answer

l

What is the output of the following C code snippet?

#include <stdio.h> 
int main() {
    int x = 5, y = 10;
    int *ptr1, *ptr2;
    ptr1 = &x;
    ptr2 = &y;
    *ptr1 = *ptr1 + *ptr2;
    *ptr2 = *ptr1 - *ptr2;
    printf("%d %d", *ptr1, *ptr2);
    return 0;
}
  • 10 5
  • 15 5
  • 10 15
  • 15 10
View Answer

15 10

What is the output of the following C code snippet?

#include <stdio.h> 
void swap(int *x, int *y) 
{
    int temp = *x;
    *x = *y;
    *y = temp;
}
int main() 
{
    int a = 5, b = 10;
    swap(&a, &b);
    printf("%d %d", a, b);
    return 0;
}
  • 5 10
  • 10 5
  • 0
  • 10 15
View Answer

10 5

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int x = 5;
    int *ptr1 = &x;
    int **ptr2 = &ptr1;
    printf("%d", **ptr2);
    return 0;
}
  • 5
  • 1
  • 0
  • Error
View Answer

5

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[5] = {1, 2, 3, 4, 5};
    int *ptr = arr + 2;
    printf("%d", *ptr);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

3

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    char str1[] = "hello";
    char *str2 = str1;
    printf("%c", *(str2+1));
    return 0;
}
  • h
  • e
  • l
  • o
View Answer

e

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[] = {1, 2, 3, 4, 5};
    int *ptr = arr;
    printf("%d", *(ptr+3));
    return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

4

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[] = {1, 2, 3, 4, 5};
    int *ptr = arr;
    printf("%d", ptr[2]);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

3

What is the output of the following C code snippet?

#include <stdio.h> 
int main() {
    int a = 5, b = 10;
    int *p1, *p2;
    p1 = &a;
    p2 = &b;
    p1 = p2;
    *p1 = 15;
    printf("%d %d", a, b);
    return 0;
}
  • 5 10
  • 10 5
  • 15 10
  • 10 15
View Answer

15 10

What is the output of the following C code snippet?

#include <stdio.h> 
int main()
 {
    char str[] = "hello";
    char *p = str;
    while (*p != '\0') 
    {
        printf("%c", *p);
        p++;
    }
    return 0;
}
  • hello
  • h
  • llo
  • olleh
View Answer

hello

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[] = {1, 2, 3, 4, 5};
    int *p = arr + 3;
    printf("%d", *(p-2));
    return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

2

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[] = {1, 2, 3, 4, 5};
    int *p1 = arr, *p2 = arr + 3;
    printf("%d", *p2 - *p1);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

4

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[] = {1, 2, 3, 4, 5};
    int *p = arr + 2;
    printf("%d", *(p+1));
    return 0;
}
  • 1
  • 2
  • 4
  • 5
View Answer

5

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[] = {1, 2, 3, 4, 5};
    int *p = arr + 3;
    printf("%d", p[-2]);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

2

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int a = 5, b = 10;
    int *p1, *p2;
    p1 = &a;
    p2 = &b;
    *p1 = *p2;
    *p2 = 15;
    printf("%d %d", a, b);
    return 0;
}
  • 15 10
  • 10 15
  • 15 15
  • 10 10
View Answer

10 15

What is the output of the following C code snippet?

#include <stdio.h> 
int main()
 {
    int arr[] = {1, 2, 3, 4, 5};
    int **p = (int **) malloc(sizeof(int *) * 5);
    for (int i = 0; i < 5; i++) 
    {
        p[i] = &arr[i];
    }
    printf("%d", **p);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

1

What is the output of the following C code snippet?

#include <stdio.h> 
int main()
 {
    int a = 5, b = 10;
    int *p1, **p2;
    p1 = &a;
    p2 = &p1;
    **p2 = b;
    printf("%d %d", a, b);
    return 0;
}
  • 5 10
  • 10 5
  • 10 10
  • 5 5
View Answer

10 10

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int a = 5;
    int *p1, **p2;
    p1 = &a;
    p2 = &p1;
    printf("%d", *p2 == &a);
    return 0;
}
  • 0
  • 1
  • Compiler Error
  • Segmentation Fault
View Answer

1

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[] = {1, 2, 3, 4, 5};
    int *p = arr;
    int **pp = &p;
    printf("%d", **pp + 2);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

4

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[] = {1, 2, 3, 4, 5};
    int *p = arr;
    int **pp = &p;
    *pp += 2;
    printf("%d", **pp);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
View Answer

3

What is the output of the following C code snippet?

#include <stdio.h> 
int main() 
{
    int arr[] = {1, 2, 3, 4, 5};
    int *p = arr + 3;
    int **pp = &p;
    printf("%d", (*--*pp)++);
    printf("%d", **pp);
    return 0;
}
  • 3 3
  • 4 4
  • 4 3
  • 3 4
View Answer

3 4

What is the output of the following C code snippet?

#include <stdio.h> 
struct student
{
    char name[20];
    int age;
};

int main() 
{
    struct student *ptr, s1;
    ptr = &s1;
    ptr->age = 20;
    strcpy(ptr->name, "Alex");
    printf("%s %d", s1.name, s1.age);
    return 0;
}
  • Alex 20
  • 20 Alex
  • Compiler Error
  • Segmentation Fault
View Answer

Alex 20

What is the output of the following C code snippet?

#include <stdio.h> 
struct employee 
{
    int emp_id;
    char emp_name[20];
    int age;
};

void change_age(struct employee *e, int new_age)
 {
      e->age = new_age;
}

int main() 
{
    struct employee emp1 = {1, "John", 25};
    change_age(&emp1, 30);
    printf("%d %s %d", emp1.emp_id, emp1.emp_name, emp1.age);
    return 0;
}
  • 1 John 25
  • 1 John 30
  • Compiler Error
  • Segmentation Fault
View Answer

1 John 30

What is the output of the following C code snippet?

#include <stdio.h> 
struct employee
 {
    int emp_id;
    char emp_name[20];
    int age;
};

int main() 
{
    struct employee emp[] = {{1, "John", 25}, {2, "Alex", 30}};
    struct employee *ptr = emp;
    printf("%d %s %d", ptr->emp_id, ptr->emp_name, ptr->age);
    return 0;
}
  • 1 John 25
  • 2 Alex 30
  • Compiler Error
  • Segmentation Fault
View Answer

1 John 25

What is the output of the following C code snippet?

#include <stdio.h> 
struct status
 {
    unsigned int error : 1;
    unsigned int warning : 2;
    unsigned int info : 3;
};

int main() 
{
    struct status s = {0, 2, 5};
    printf("%d %d %d", s.error, s.warning, s.info);
    return 0;
}
  • 0 2 5
  • 1 2 5
  • 0 1 5
  • Compiler Error
View Answer

1 2 5

What is the output of the following C code snippet?

#include <stdio.h> 
struct flags {
    unsigned int flag1 : 1;
    unsigned int flag2 : 1;
    unsigned int flag3 : 1;
};
int main() {
    struct flags f = {1, 0, 1};
    if (f.flag1 && !f.flag2 && f.flag3) {
        printf("True");
    } else {
        printf("False");
    }
    return 0;
}
  • True
  • False
  • Compiler Error
  • Segmentation Fault
View Answer

True

What is the output of the following C code snippet?

#include <stdio.h> 
struct bits 
{
    unsigned int a : 5;
    unsigned int b : 5;
    unsigned int c : 5;
    unsigned int d : 5;
};
int main() 
{
    struct bits bits1 = {0x1f, 0x1f, 0x1f, 0x1f};
    printf("%d %d %d %d", bits1.a, bits1.b, bits1.c, bits1.d);
    return 0;
}
  • 31 31 31 31
  • 1 1 1 1
  • Compiler Error
  • Segmentation Fault
View Answer

1 1 1 1

What is the output of the following C code snippet?

#include <stdio.h> 
struct 
{
    int a : 4;
    int b : 4;
} var;
int main() 
{
    var.a = 4;
    var.b = 5;
    printf("%d %d", var.a, var.b);
    return 0;
}
  • 4 5
  • 5 4
  • 0 5
  • Compiler Error
View Answer

4 5

What is the output of the following C code snippet?

#include <stdio.h> 
struct bits {
    unsigned int a : 5;
    unsigned int b : 5;
    unsigned int c : 5;
    unsigned int d : 5;
};
int main() {
    struct bits bits1 = {0x1f, 0x1f, 0x1f, 0x1f};
    bits1.a &= 0x0f;
    bits1.b &= 0x0f;
    bits1.c &= 0x0f;
    bits1.d &= 0x0f;
    printf("%d %d %d %d", bits1.a, bits1.b, bits1.c, bits1.d);
    return 0;
}
  • 15 15 15 15
  • 1 1 1 1
  • Compiler Error
  • Segmentation Fault
View Answer

15 15 15 15

What will be the output of the above program?

#include 
int main() 
{
    char *arr[] = {"apple", "orange", "banana"};
    printf("%s", arr[1]);
    return 0;
}
  • apple
  • orange
  • banana
  • Compilation Error
View Answer

orange

What is the output of the following code?

#include 
int main() {
int a = 5;
int *p = &a;
char *q = (char *)p;
*q = 10;
printf("%d", *p);
return 0;
}
  • 5
  • 10
  • Compile error
  • Runtime error
View Answer

10

What type of error is caused by the following code snippet?

int main() 
{
   printf("The value of pi is: %f", 3.14);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

Compile error

What type of error is caused by the following code snippet?

int main() 
{
   printf("The value of pi is: %f", 3.14);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

Compile error

What type of error is caused by the following code snippet?

int main() 
{
   int arr[5] = {1, 2, 3, 4, 5};
   printf("%d", arr[10]);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

Runtime error

What type of error is caused by the following code snippet?

int main() 
{
   int* ptr = NULL;
   printf("%d", *ptr);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

Segmentation fault

What type of error is caused by the following code snippet?

int main() 
{
   char* str = "Hello";
   str[0] = 'h';
   printf("%s", str);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

Runtime error

What type of error is caused by the following code snippet?

int main() {
   int* ptr = malloc(sizeof(int));
   free(ptr);
   *ptr = 5;
   printf("%d", *ptr);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

Runtime error

What type of error is caused by the following code snippet?

void foo(int arr[]) 
{
   printf("%d", arr[0]);
}

int main() 
{
   int arr[5] = {1, 2, 3, 4, 5};
   foo(arr);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

No error

What type of error is caused by the following code snippet?

int main() 
{
   int a = 5, b = 0;
   int c = a/b;
   printf("%d", c);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

Runtime error

What type of error is caused by the following code snippet?

int main()
 {
   int arr[5] = {1, 2, 3, 4, 5};
   int* ptr = &arr;
   printf("%d", *ptr);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

Compile error

What type of error is caused by the following code snippet?

int main() {
   int* ptr = malloc(-1);
   printf("%d", *ptr);
   return 0;
}
  • Compile error
  • Runtime error
  • Segmentation fault
  • No error
View Answer

Runtime error

What will be the output of the program?

#include <stdio.h>
#include <stdlib.h>
int main() 
{
    int *p = NULL;
    *p = 10;
    printf("%d", *p);
    return 0;
}
  • 10
  • 0
  • Compilation Error
  • Segmentation Fault
View Answer

Segmentation Fault

What will be the output of the program?

#include <stdio.h> 
#include <string.h>
int main() 
{
    char *str = "Hello, World!";
    strcpy(str, "Goodbye, World!");
    printf("%s", str);
    return 0;
}
  • Hello, World!
  • Goodbye, World!
  • Compilation Error
  • Segmentation Fault
View Answer

Segmentation Fault

 What will be the output of the above program?

#include <stdio.h>

int x = 0;

int main()

{

int *const ptr = &x;

printf(“%p\n”, ptr); ptr++;

printf(“%p\n”, ptr); return 0;

}

  • 0 1
  • Compile error
  • Runtime error
  • Segmentation fault
View Answer

Compile error

What will be the output of the C program?
#include
int main()
{
printf(“”%d “”,sizeof(2.5));
printf(“”%d “”,sizeof(2));
printf(“”%d””,sizeof(‘A’));
return 0;
}

  • 8 4 4
  • 8 4 1
  • 4 4 1
  • 2.5 2 A
View Answer
8     4   4    

What will be the output of the C program?
#include
int main()
{
float x = 3.14;
double y = 3.14;
printf(“”%f %ff””,x, y);
return 0;
}

  • Runtime error
  • Compilation error
  • 3.140000 3.140000
  • 3.140000 3.140000f
View Answer
3.140000 3.140000f

What will be the output of the C program?
#include
int main()
{
int x = 2;
(x & 1) ? printf(“”true””) : printf(“”false””);
return 0;
}

  • Compilation error
  • TRUE
  • FALSE
  • Runtime error
View Answer
FALSE

What will be the output of the C program?
#include
int main()
{
char num = ‘\010’;
printf(“”%d””, num);
return 0;
}

  • 10
  • 8
  • 10
  • 8
View Answer
8

What will be the output of the C program?
#include
#define x =
int main()
{
int a;
a x 5;
printf(“”%d””,a);
return 0;
}

  • Compilation error
  • Runtime error
  • 5
  • program incomplete
View Answer
5

What will be the output of the C program?
#include
int main(){
int i = -1;
do
{
printf(“”HiDoWhile “”);
}while(i++);
return 0;
}

  • Compilation Error
  • HiDoWhile
  • HiDoWhileHiDoWhie
  • HiDoWhile

View Answer
HiDoWhile HiDoWhile

What will be the output of the C program?
#include
int main(){
while(printf(“”%d””, 5) < 4)
printf(“”Loop “”);
return 0;
}

  • Prints Nothing
  • 5Loop 5Loop 5Loop 5Loop 5Loop
  • 5Loop
  • Infinite iterations or Infinite Loop
View Answer
Infinite iterations or Infinite Loop

What will be the output of the C program?
#include
#define FALSE -1
#define NULL 0
#define TRUE 1

int main(){
if(NULL)
printf(“”NULL””);
else if(FALSE)
printf(“”TRUE””);
else
printf(“”FALSE””);
return 0;
}

  • FALSE
  • TRUE
  • NULL
  • Compilation Error
View Answer
TRUE

What will be the output of the C program?
#include
int main(){
int i = 0, j = 0;
if(i++ == j++)
printf(“”%d %d””, i–, j–);
else
printf(“”%d %d””, i, j);
return 0;
}

  • 0 0
  • 0 1
  • 1 0
  • 1 1
View Answer
1   1

What will be the output of the C program?
#include
#define loop for(;;)
int main()
{
printf(“”DONE””);
loop;
return 0;
}

  • Compilation error
  • Done
  • Program never ends
  • None of the above
View Answer
Program never ends

What will be the output of the C program?
#include
int main()
{
char i = 0;
for(;i>=0;i++);
printf(“”%d””, i);
return 0;
}

  • Compilation error
  • -128
  • 0
  • 1
View Answer
-128

What will be the output of the C program?
#include
int main()
{
int i;
if(scanf(“”%d””,&i)) //if we give input as 0
printf(“”inside if block””);
else
printf(“”inside else block””);
return 0;
}

  •  Runtime error
  • Compilation error
  • inside else block
  • inside if block
View Answer
inside if block

What will be the output of the C program?
#include
int main(){
int i = 3, j = 4;
switch(i | j)
{
case 1:
printf(“”inside case 1″”);
break;
case 3:
printf(“”inside case 3″”);
break;
case 4:
printf(“”inside case 4″”);
break;
case 7:
printf(“”inside case 7″”);
break;
}
return 0;
}

  • inside case 1
  • inside case 3
  • inside case 7
  • inside case 4
View Answer
inside case 7

What will be the output of the C program?
#include
#define preprocessor(n) printf (“”macro”” #n “” = %d””, macro##n)
int main(void) {
int macro25 = 47;
preprocessor(25);
return 0;
}

  • Compilation error
  • macro25 = 47
  • macro47 = 25
  • Runtime error
View Answer
macro25 = 47

What is the output of following program?
# include

int main()
{
char str1[] = “”GeeksQuiz””;
char str2[] = {‘G’, ‘e’, ‘e’, ‘k’, ‘s’, ‘Q’, ‘u’, ‘i’, ‘z’};
int n1 = sizeof(str1)/sizeof(str1[0]);
int n2 = sizeof(str2)/sizeof(str2[0]);
printf(“”n1 = %d, n2 = %d””, n1, n2);
return 0;
}

  • n1 = 10, n2 = 9
  • n1 = 10, n2 = 10
  • n1 = 9, n2 = 9
  • n1 = 9, n2 = 10
View Answer
n1 = 10, n2 = 9

In below program, what would you put in place of “?” to print “”Cranesvarsity”?
#include
int main()
{
char arr[] = “”Cranesvarsity””;
printf(“”%s””, ?);
return 0;
}

  • arr
  • (arr+5)
  • (arr+4)
  • Not possible
View Answer
arr

What will be the output of the program?
#include
int addmult(int ii, int jj)
{
int kk, ll;
kk = ii + jj;
ll = ii * jj;
return (kk, ll);
}
int main()
{
int i=3, j=4, k, l;
k = addmult(i, j);
l = addmult(i, j);
printf(“”%d %d””, k, l);
return 0;
}

  • 12 12
  • No error, No output
  • Error: Compile error
  • None of above
View Answer
12       12

What will be the output of the program?
#include
int fun(int i)
{
i++;
return i;
}
int main()
{
int fun(int);
int i=3;
fun(i=fun(fun(i)));
printf(“”%d””, i);
return 0;
}

  • 5
  • 4
  • error
  • Garbage value
View Answer
5

#include
int fun()
{
static int num = 16;
return num–;
}
int main()
{
for(fun(); fun(); fun())
printf(“”%d “”, fun());
return 0;
}

  • Infinite loop
  • 13 10 7 4 1
  • 14 11 8 5 2
  • 15 12 8 5 2
View Answer
14   11  8  5  2

#include
int main()
{
int x = 10;
static int y = x;

if(x == y)
printf(“”Equal””);
else if(x > y)
printf(“”Greater””);
else
printf(“”Less””);
return 0;

  • compiler error
  • equal
  • greater
  • less
View Answer
compiler error

Which of the following statement are correct?
(I) The maximum value a variable can hold depends upon its storage class.
(II) By default all variables enjoy a static storage class.

  • Only I is correct
  • Only II is correct
  • Both I & II are correct
  • Both I & II are incorrect
View Answer
Both I & II are incorrect

What will be the output of the following program?
#include
int main()
{
register int i = 2;
static char ch = ‘A’;
auto float j;
int k;
k = ++ch && i;
k = ++ch;
j = i– + ++k * 2;
printf(“%d %f”, k , j);
return 0;
}

  •  B 3
  • 65 138.000000
  • 68 138.000000
  • A 138
View Answer
68        138.000000

What will be the output of the following code?
#include< stdio.h>
int main()
{
extern int a=0;
static char j = ‘E’;
printf(“%c %d”, ++j, ++a);
return 0;
}

  • E 1
  • F 1
  • F Garbage
  • Compler error
View Answer
compiler error

What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?
#include
int main()
{
int a[3][4]={1,2,3,4,4,3,2,1,7,8,9,0};
printf(“%u,%u”,a+1,&a+1);
}

  • 65474, 65488
  • 65480, 65488
  • 65480, 65496
  • 65474, 65476
View Answer
65480, 65496

Predict output of following program
int main()
{
int i;
int arr[5] = {1};
for (i = 0; i < 5; i++)
printf(“”%d “”, arr[i]);
return 0;
}

  • 1 followed by four garbage values
  • 1 0 0 0 0
  • 1 1 1 1 1
  • 0 0 0 0 0
View Answer
1 0 0 0 0

Predict output of following program
#include
int main()
{
char p;
char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8};
p = (buf + 1)[5];
printf(“”%d””, p);
return 0;
}

  • 5
  • 6
  • 9
  • None of the above
View Answer
9

What will be the output of the program ?
#include
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf(“”%d, %d, %d””, i, j, m);
return 0;
}

  • 2 1 15
  • 1 2 5
  • 3 2 15
  • 2 3 20
View Answer
3  2  15

What will be the output of the program?
#include
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
printf(“”%d, “”, arr[i]);
return 0;
}

  • 1 , 2, 3, 4, 5
  • Garbage value, 1, 2, 3, 4
  • 0, 1, 2, 3, 4
  • 2, 3, 4, 5, 6
View Answer
Garbage value, 1, 2, 3, 4

What will be the output of the C program?
#include
int function();
main()
{
int i;
i = function();
printf(“”%d””, i);
return 0;
}
function()
{
int a;
a = 250;
return 0;
}

  • Runtime error
  • 0
  • 250
  • no output

What will be the output of the program ?
#include
int main()
{
int arr[1]={10};
printf(“”%d””, 0[arr]);
return 0;
}

  • 1
  • 10
  • 0
  • 6
View Answer
10

#include
int main()
{

while((printf(“”Hello “”))<4)
{
printf(“”The control is inside the while loop””);
}

printf(“”The control is outside the while loop\n””);

return 0;
}
What will be the output of the program ?

  • Hello
  • Hello The control is outside the while loop
  • The control is outside the while loop
  • Compliler Error
View Answer
Hello The control is outside the while loop

int main()
{
int x = 10;
{
int x = 0;
printf(“”%d””,x);
}
return 0;
}

  • 10
  • Compilation Error
  • 0
  • Undefined

Which programming language is more faster among these?

  • Java
  • PHP
  • C
  • Visual Basic
View Answer
C

int main()
{
int a = printf (“”hello””);
printf(“”%d””, a);
return 0;
} After executing the above program the value of a is:

  • 0
  • 1
  • 5
  • Garbage value
View Answer
5

#include
int main()
{
int n;
for(n = 7; n!=0; n–)
printf(“”n = %d””, n–);
getchar();
return 0;
}

  • 7 6 5 4 3 2 1
  • 7 5 3 1
  • 6 4 2
  • Infinite loop
View Answer
Infinite loop

#include
int main()
{
printf(“”%x””, -1<<1);
getchar();
return 0;
}

  • 0x01
  • 0x05
  • ffffe
  • fffffffe
View Answer
ffffffe

#include
#include
enum {false, true};
int main()
{
int i = 1;
do
{
printf(“”%d\\n””, i);
i++;
if (i < 15)
continue;
} while (false);

return 0;
}

  • 1\n
  • 1
  • Error
  • Infinite Loop
View Answer
1\n

#include
int main()
{
static int i=5;
if(–i){
main();
printf(“”%d “”,i);
}
}

  • 5 4 3 2 1
  • 4 3 2 1 0
  • 0 0 0 0
  • Compile time error
View Answer
0 0 0 0 0

#include
int main()
{
int x;
printf(“”%d””,scanf(“”%d””,&x));
return 1;
}

  • 0
  • 2
  • 3
  • 1
View Answer
1

#include
int main()
{
int i=0;
for(i=0; i<20; i++)
{
switch(i)
{
case 0:
i+=5;
case 1:
i+=2;
case 5:
i+=5;
default:
i+=4;
break;
}
printf(“”%d “”, i);
}
getchar();
return 0;
}

  • 14 24
  • 10 22
  • 16 21
  • Compile time error
View Answer
16 21

#include
int main()
{
printf(“”%p””, main);
getchar();
return 0;
}

  • Compile time error
  • Run time error
  • Address of main
  • No output
View Answer
Address of main

#include
# include
void fun(int *a)
{
a = (int*)malloc(sizeof(int));
}
int main()
{
int *p;
fun(p);
*p = 6;
printf(“”%d\\n””,*p);
return(0);
}

  • 6
  • Run time error
  • Syntatical error
  • No output
View Answer
No output

What will be the output of following?
void main()
{
int const* p = 5;
printf(“”%d””, ++(*p));
}

  • 6
  • 5
  • Garbage Value
  • Compiler Error
View Answer
Compiler Error

What will be the output of following?
#include

int main()
{
int i=0;

i=printf(“”Where there is a will there is way “”);
printf(“”%d\n””,i);
return 0;
}

 

  • Where there is a will there is way 9
  • Where there is a will there is way 35
  • Where there is a will there is way 34
  • Compiler Error
View Answer
Where there is a will there is way 35

What will be the output of following?
void main()
{
int m, i = 0, j = 1, k = 2;
m = i++ || j++ || k++;
printf(“”%d %d %d %d””, m, i, j, k);
}

  • 1 1 2 3
  • 1 1 2 2
  • 0 1 2 2
  • 0 1 2 3
View Answer
1 1 2 2

What will be the output of following?
void main()
{
int i = 0;
printf(“”%d %d””, i, i++);
}

  • 1 0
  • 0 1
  • 0 0
  • 1 1
View Answer
1 0

What will be the output of following?
#include
#include
void main()
{
printf(“”%d %d””, sizeof(“”program””), strlen(“”program””));
}

  • 7 7
  • 8 8
  • 8 7
  • 7 8
View Answer
8 7

What will be the output of following?
#include
int main()
{
int array[] = {[1] = 1, [0] = 2, [2] = 3 };
printf(“”%d %d %d””, array[0], array[1], array[2]);
return 0;
}


2 1 3
1 3 2
1 0 2
Error

View Answer
2 1 3

What will be the output of following?
#include
char A()
{
char c = ‘B’;
return c;
}

int main()
{
printf(“”%lu””, sizeof(A()));
return 0;
}

  • 0
  • Error
  • 2
  • 1
View Answer
1

#include

int main()
{
int i=0;

for (;;);
printf(“”INDIA\n””);
return 0;
}

What will be the output for the above program?

  • The string “INDIA” is printed one time
  • Compilation Error
  • The string “INDIA” is printed infiite times
  • The string” INDIA” will never be printed
View Answer
The string” INDIA” will never be printed

What does the following fragment of C-program print?
char c[] = “”GATE2011″”;
char *p =c;
printf(“”%s””, p + p[3] – p[1]) ;

 

  • GATE2011
  • E2011
  • 11
  • 2011
View Answer
2011

#include

main()
{
int x = 5;

if(x=5)
{
if(x=5) break;
printf(“”Hello””);
}
printf(“”Hi””);
}

  • 1
  • 1 2
  • No output
  • Compile error
View Answer
compiler error

#include

int main()
{
int i,j,return_val=0;

for(i=0,j=4; i < 5 && j < 10 ;i++,j–)
{
printf(“”%d%d “”,i,j);
}
}

  • 04 13 22 31 40
  • 04 13 22 31 40 5-1 6-2 7-3 8-4 9-5
  • 04 13 22 31 40 5-1 6-2 7-3 8-4
  • Compliler Error
View Answer
04 13 22 31 40

#include

int main()
{
int i=0,*s=NULL;
int *ptr = &i;
char str[] = “”Welcome””;

s = str;
while(*s)
printf(“”%c””, *s++);
return 0;
}

  • Welcome
  • 0
  • Wel
  • Wo
View Answer
Wo

If S is an array of 80 characters, then the value assigned to S through the statement scanf(“%s”,S) with input 12345 would be

  • “12345”
  • nothing since 12345 is an integer
  • S is an illegal name for string
  • %s cannot be used for reading in values of S
View Answer
“12345”

A one dimensional array A has indices 1….75.Each element is a string and takes up three memory words. The array is stored starting at location 1120 decimal. The starting address of A[49] is

  • 1167
  • 1164
  • 1264
  • 1169
View Answer
1264

#include
int main()
{
int a=0,b=0,c=0,d=0,e=a,f=b,g=c;

a=b=c=d=5;//e=f=g=5;

printf(“” %d %d %d %d %d %d %d””,a,b,c,d,e,f,g);
return 0;
}

  • 5 5 5 5 0 0 0
  • 0 0 0 5 0 0 0
  • Compilation error
  • 5 5 5 5 5 5 5
View Answer
5 5 5 5 0 0 0

#include
int main()
{
int num=0x12345678;
printf(“”%x\n””,num=num>>1);
return 0;
}

  • 91a2b3c
  • 1234567
  • 2345678
  • None of these
View Answer
91a2b3c

#include
int main()
{
int num=0x82345678;
printf(“”%x\n””,num=num>>1);
return 0;
} What will be the output?

  • c11a2b3c
  • 411a2b3c
  • 8234567
  • None of the above
View Answer
c11a2b3c

#include
  void main()
  {
    char str1[10]=””abyz””;
    int i;
        for(i=0; i<4; i++)
        {
             printf(“”%c””,str1[i] – 32);
        }
  }

  • AB
  • zyba
  • abyz
  • ABYZ
View Answer
ABYZ