MCQ

100 Multiple Choice Questions In C Programming – Part 13

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

1. Which keyword is used to prevent any modification of a variable in a C program?

A volatile

B const

C immutable

D mutable

B
The keyword “const” stands for a constant in a C program.

 

 

2. Which of the following is not a declaration of a pointer?

A char *str;

B char a[10];

C char a;

D char a[] = {‘10’, ‘20’, ‘30’, ‘40’};

C
An array is a constant pointer to the first element of the array.

 

 
 

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

void main()
{
     int var = 6;
     float var = 6;
     printf("%d", var )
}

A 6.0000000

B 6.8

C 6

D Compilation error

D
Since the variable “var” is defined as both “int” and “float”, it causes an error. The output is as follows:

$ cc prog1.c
prog1.c: In function ‘main’:
prog1.c:5: error: conflicting types for ‘var’
prog1.c:4: note: previous definition of ‘var’ was here
prog1.c:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘double’
prog1.c:7: error: expected ‘;’ before ‘}’ token

 

 

4. Which statement is false?

A A variable refers to a position in the memory

B A variable must be declared and defined at the same time

C A single variable cannot be defined with two different types in the same scope

D A variable that has been defined previously can be defined again with a different scope

B
It is not an error, if the variable is declared and not defined.

 

 

5. Can a variable declared in a function be used in the main() function?

A False

B True

C True if it is declared static

D True if it is declared static

A
Since the scope of a variable declared in a function is limited only in that function, the statement is false.

 

 
 

6. The variable name used in one function cannot be used in another function?

A False

B True

C Maybe

D None of the above

A
Since the scope of a variable declared in a function is limited only within that function, the same name can be used to declare another variable in another function.

 

 

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

int main()
{
     enum {STRAWBERRY = 6, BANANA, APPLE = 2, AUBERGINE};
     printf("AUBERGINE = %d\n", AUBERGINE);
}

A AUBERGINE = 3

B AUBERGINE = 2

C AUBERGINE = 6

D AUBERGINE = 7

A
An enum element’s value depends on the value assigned to the previous element. The output is as follows:

$gcc prog1.c
$ a.out
AUBERGINE = 3

 

 

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

int main()
{
     printf("C Programming %s", "Function by\n%s StackHowTo", "WWW");
}

A

C Programming Function by
    WWW StackHowTo

B

C Programming Function by\n%s StackHowTo

C

C Programming Function by
    %s StackHowTo

D Compilation error

C
This program has only one %s in the first quotes ” “, so it does not read the string “WWW”. The output is as follows:

$gcc prog1.c
$ a.out
C Programming Function by
   %s StackHowTo

 

 
 

9. The pointer “str” contains a reference to which string ____?
char * str = "Hello\0" "World!";

A Hello

B Hello\0world!

C Helloworld!

D Invalid statement

A
‘\0’ is accepted as a char in the string.

#include <stdio.h>
#include <string.h>

int main()
{
    char * str = "Hello\0" "World!";
    printf("%s", str);
    return 0;
}

Output:

Hello

 

 

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

int main()
{
    const int x = 7;
    printf("x = %d\n", x);
}

A x = 7

B x = 20

C Compilation error

D Runtime error

C
#define replaces x with 20, the identifier will be replaced by a value, since x is a constant, we can’t change it and therefore a compilation error. The output is as follows:

$gcc prog2.c
$ a.out
prog2.c: In function ‘main’:
prog2.c:5: error: expected identifier or ‘(’ before numeric constant

 

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 *