MCQ

100 Multiple Choice Questions In C Programming – Part 10

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

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

void main()
{
   int y = 5 * 9 / 3 + 9;
}

A 24

B 3

C 2.68

D Depends on compiler

A

 

 
 

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

void main()
{
   int y = 5.3 % 2;
   printf("The value of y is %d", y);
}

A The value of y is 0,3

B The value of y is 1

C The value of y is 2,3

D Compilation error

D
We cannot perform the modulo between a value of type double and a value of type int. The output is as follows:

$ gcc main.c
$ a.out
main.c: In function ‘main’:
main.c:5:21: error: invalid operands to binary % (have ‘double’ and ‘int’)
         int y = 5.3 % 2;
                     ^

To perform this type of operation we use the function “fmod()” which can be found in the “math.h” library as follows:

#include <stdio.h>
#include <math.h>

void main()
{
    int y = fmod(5.3, 2) ;
    printf("The value of y is %d", y);
}

 

 

 

3. What happens in the memory with the following code?
malloc(sizeof(int) * 25);

A This reserves memory for an integer of 25 bytes

B This reserves memory for an array of 25 integers

C This reserves memory for an array of 25 bytes

D This reserves memory for an array of 25 char

B

 

 

4. Dynamic memory allocation follows steps in a particular order, which one?

A malloc, use memory, check successful allocation, free

B malloc, use memory, free, check successful allocation

C free, check successful allocation, malloc, use memory

D malloc, check successful allocation, use memory, free

D

 

 
 

5. How to initialize a pointer to an array of 10 char?

A p = malloc (10);

B p = (char *) malloc(10,1);

C p = (char *) malloc (sizeof(10*char));

D p = (char *) malloc(10 * sizeof(char));

D

 

 

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

void main()
{
    int x = 3;
    int y = ++x + x++ + --x;
    printf("Value of y is %d", y);
}

A Value of y is 10

B Value of y is 13

C Value of y is 12

D Undefined value

B

 

 

7. Determine the priority of each operator (highest to lowest)?

A +, -, %, *, /

B %, +, -, *, /

C %, +, /, *, –

D %, *, /, +, –

D

 

 

8. Which of the following is not an arithmetic operation?

A x %= 10;

B x != 10;

C x /= 10;

D x *= 10;

B
The operator ” != ” used to check inequality.

 

 
 

9. Which of the following data types will generate an error on the modulo % operation?

A float

B int

C short

D char

A
To execute the modulo between float values, we can use the function “fmod()” from the standard math library. Its prototype can be found in the standard header <math.h>.

 

 

10. Which of the following options are the basic arithmetic operators, i.e. the execution of the desired operation can be done using only this operator?

A +, -, *, /, %

B +, -, *, /

C +, -, %

D +, –

D
The + and – operators are the basic operators.

 

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 *