MCQ

100 Multiple Choice Questions In C Programming – Part 8

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

1. With which value should a pointer be initialized?

A 0

B NULL

C -1

D None of the above

B
Pointer should be initialized with NULL.

 

 
 

2. According to the following statements, what is the output of “p2”?
int A = 5;
int *p1 = &A; // p1 points to A
int **p2 = &p1; // p2 points to p1

A The value of A

B The address of p1

C The address of A

D None of the above

B
A pointer is an object (Lvalue) whose value is equal to the address of another object. A pointer is declared by the following instruction:

type *pointer-name;

Where type is the type of the pointed object. This declaration declares an identifier, ‘pointer-name’, associated with an object whose value is the address of another object. The identifier ‘pointer-name’ is an address identifier. As for any Lvalue, its value is modifiable.
 

 

 

3. The function tolower() defined in the C library works for ___?

A Ascii character set

B Ascii and utf-8 but not the EBSIDIC character set

C Unicode character set

D Any set of characters

D
The function tolower() takes an uppercase alphabet and converts it to lowercase.

 

 

4. What is the output of the code below considering the size of “short int” is 2, “char” is 1 and “int” is 4 bytes?
#include <stdio.h>

int main()
{
     short int a = 20;
     char b = 97;
     printf("%d, %d, %d\n", sizeof(a), sizeof(b), sizeof(b + a));
     return 0;
}

A 2, 1, 1

B 2, 1, 4

C 2, 1, 2

D 2, 2, 8

B
Whenever you have an operator like (+ – * / % << >> & | ^ == != < <= > >=) between two operands of different types, the two types are converted to a common type before the operation is performed.

 

 
 

5. Which type conversion is NOT accepted?

A char –> int

B double –> char

C int –> char

D float –> char *

D
The conversion of float to char* is not allowed.

 

 

6. Which of the following will be the type of ‘res’?
res = (float)x * (int)y / (long)w * (double)z

A double

B float

C long

D int

A
If both operands are “int” or “char”, the result is “int”. If both are “float” or “doubles”, the result is “double”.

 

 

7. Which of the following type-casting can be “wrapped”?

A char –> int

B int –> float

C int –> char

D char –> short

C
Example:

int i = 48;
char c = (char)i;

 

 

8. Which of the following type-casting is accepted in C?

A Implicit type conversion

B Explicit type conversion

C Both

D None of the above

C
Implicit type conversion Also called “automatic type conversion”. Done by the compiler, without any user intervention. Explicit type conversion – This process is also called “Type casting” and defined by the user. Here is the syntax in C:

(type) expression;

 

 
 

9. When should you use type-casting?

A The value to be stored exceeds the maximum limit

B The value to be stored is not supported by this data type

C To reduce the memory used, according to the value

D All the answers are true

D
You should use type-casting when:

  • The value to be stored exceeds the maximum limit
  • The value to be stored is not supported by this data type
  • To reduce the memory used, according to the value

 

 

10. Which of the following codes creates an array of 5 integers?

A int arr(5);

B int *arr[5];

C int arr[4];

D int arr[5];

D
To create an array of 5 integers use int arr[5];.

 

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 *