MCQ

100 Multiple Choice Questions In C Programming – Part 11

This collection of 100 Multiple Choice Questions and Answers (MCQs) In C Programming : Quizzes & Practice Tests with Answer focuses on “C Programming”.
 

1. We want to change the size of an array ‘Arr’ of integers, from 10 to 11 integers ?

A Arr = (int *) malloc(11* sizeof(int));

B Arr = (int *) malloc(11);

C Arr= (int *) realloc(T, 11* sizeof(int));

D Arr = (char *) realloc(11 * sizeof (int));

C

 

 

2. P points to an array of 10 integers, we want to free the memory it occupies. So how do we do it?

A P = NULL;

B *P = 0;

C free(P);

D free(*P);

C

 

 
 

3. What is the value of “z” in this code?
#include <stdio.h>

int main()
{
    int x = 10;
    double y = 5.6;
    int c;
    int z = x + y;
    printf("Value of z is %d", z);
}

A Value of z is 10

B Value of z is 15

C Value of z is 15.6

D Value of z is 16

B

 

 

4. What is the value of “z” in this code?
#include <stdio.h>

int main()
{
    int x = 10, y = 5, w = 5;
    int d;
    int z = x == (y + w);
    printf("Value of z is %d", z);
}

A Value of z is 5

B Value of z is 1

C Value of z is 10

D Syntax error

B

 

 

5. What is the output of the following C program?
#include <stdio.h>

int main()
{
     int a = 1, b = 0, c = 3;
     a > b ? printf("%d", c) : return c;
}

A 1

B 3

C Runtime error

D Compilation error

C
Output:

error: expected expression before 'return'
a > b ? printf("%d", c) : return c;
                          ^

We cannot put “return” in a ternary condition. To perform this kind of statement we use the “if” statement as shown below:

#include <stdio.h>
 
int main()
{
    int a = 1, b = 0, c = 3;
    if(a > b )
        printf("%d", c); 
    else
        return c;
}

 

 

6. What is the output of the following C program?
#include <stdio.h>

void main()
{
    int a = 1, c = 3;
    int b = a << 3;
    printf(" %d\n", b);
}

A 8

B 1

C -724794438

D Compilation error

A
The base value in binary (a = 1) : 0000 0001
Left shift (a << 3) : 0000 1000

 

 
 

7. What is the output of the following C program?
#include <stdio.h>

void main()
{
    int a = 0, b = 2, c = 3;
    int x = a & b | c;
    printf("%d", x);
}

A 2

B 3

C 0

D Depends on compiler

B
AND bitwise

AND bitwise is a binary operator (operates on two operands). It is represented by &.
The & operator compares the corresponding bits of two operands. If both bits are 1, it gives 1. If one of the bits is not 1, it gives 0. For example the AND bitwise of a & b :

a = 0 (in decimal) = 00000000 (in binary)
b = 2 (in decimal) = 00000010 (in binary)

AND bitwise of 0 and 2

  00000000 
& 00000010
  __________
= 00000000 = 0 (in decimal)

 

OR bitwise

Or bitwise is a binary operator (operates on two operands). It is represented by |.
The | operator compares the corresponding bits of two operands. If one of the bits is 1, it gives 1. For example the OR bitwise of (a & b) | c:

(a & b) = 0 (in decimal) = 00000000 (in binary)
c = 3 (in decimal) = 00000011 (in binary)

OR bitwise of 0 and 3

  00000000
| 00000011
  __________
= 00000011 = 3 (in decimal)

 

8. What is the output of the following C program?
#include <stdio.h>

int main()
{
     int a = 0, b = 0;
     if (a && (b = a + 10))
         //do something
         ;
         ;
}

A 10

B 0

C Depends on compiler

D Depends on the standard

B
The most recent C compiler (currently C99 with some modifications) returns 0 by default, if there is no explicit return instruction at the end of the function.
 

 

 
 

9. What is the output of the following C program?
#include <stdio.h>

int main()
{
     int a = 1;
     if (a++ && (a == 1))
         printf("OK\n");
     else
         printf("KO\n");
}

A KO

B OK

C Depends on compiler

D Depends on the standard

A

 

 

10. Why is it called C++?

A Because it is the increment of the C language

B Because it is the C language plus the Javascript language

C Because it’s more elegant

D All the answers are true

A

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *