MCQ

100 Multiple Choice Questions In C Programming – Part 3

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

1. What data type can store 15.9635?

A char

B long

C double

D int

C
15.9635 corresponds to double precision floating point numbers, usually stored on 64 bits. There is also a float type giving less precision. Usually float variables are stored on 32 bits.

 

 

2. What data type can store -15?

A char

B long

C double

D int

D
Standard integer type, signed, able to represent at least the numbers [-32 768 ; +32 767]. Same as the standard integer type, but unsigned, able to represent at least the numbers [0 ; 65 535].

 

 
 

3. We want to get a decimal number entered from the keyboard, which statement is correct?

A scanf("%f",decimalNumber);

B scanf("%f",&decimalNumber);

C scanf("%lf", *decimalNumber);

D scanf("%d",decimalNumber);

B
scanf is a function declared in the <stdio.h> header, this function can be used for capturing formatted data, whether letters, numbers or strings.

%d to print integer and %f to print float value.



 

 

4. Which expression is valid?

A int my_nbr = 100, 000;

B int my_nbr = 100000;

C int my nbr = 1000;

D int $my_nbr = 10000;

B
Space, comma and $ are not allowed in a variable name.

 

 

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

int main()
{
   printf("Hello World! %d \n", x);
   return 0;
}

A Hello World! x;

B Hello World! followed by a random value

C Compilation error

D Hello World!

C
This results in an error because the variable x is used without prior declaration. The output is as follows:

$gcc prog1.c
pgm1.c: In function ‘main’:
pgm1.c:4: error: ‘x’ undeclared (first use in this function)
pgm1.c:4: error: (Each undeclared identifier is reported only once
pgm1.c:4: error: for each function it appears in.)

 

 
 

6. After the operation res = (13/5) -2, what will “res” be equal to?

A 0

B -2

C 0,6

D 2

A
In C the operator / applied to two integers, performs the integer division.

In mathematics the integer division gives two results:
– The quotient
– The remainder

13/5 gives
– The quotient = 2
– The remainder = 3
13 = 5 * 2 + 3

In C, the / operator gives the quotient and the % operator gives the remainder
13/5 gives the quotient = 2
13%5 gives the remainder = 3

13 = 5 * (13/5) + 13%5

So: res = 2 – 2 = 0

 

 

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

int main()
{
    int y = 8000;
    int y = 4;
    printf("Hello World! %d\n", y);
    return 0;
}

A Compilation error

B Hello World! 4

C Hello World! 8000

D Hello World! followed by a random value

A

Since y is already defined, redefinition causes an error. The output is as follows:

$gcc prog2.c
pgm2.c: In function ‘main’:
pgm2.c:5: error: redefinition of ‘y’
pgm2.c:4: note: previous definition of ‘y’ was here

 

 
 

8. Which of these functions should I use to round 2.5 to 2?

A pow

B ceil

C floor

D sqrt

C
In C, “ceil” function used to round up and “floor” function used to round down.

 

 

9. Which of the following is not a valid statement?

A float PI = 3.14;

B double PI = 3.14;

C int PI = 3.14;

D #define PI 3.14

D
#define PI 3.14 is a preprocessor, to make a textual substitution.

 

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

int main()
{
    int main = 9;
    printf("%d", main);
    return 0;
}

A This will cause a compile error

B This will cause a runtime error

C It will run without error and displays 9

D It goes into an infinite loop

C
In a C program, you may encounter the same name of a function and the same name of a variable. The program will display:

$gcc prog3.c
$ a.out
9

 

 
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 *