Search Tutorials


C Variables MCQ Questions and Answers | JavaInUse

C Variables MCQ Questions and Answers

Q. What is a variable in C programming?

A. A named storage location
B. A reserved keyword
C. A constant value
D. A data type

Q. What is the correct syntax to declare a variable in C?

A. <code>datatype variable_name;</code>
B. <code>variable_name datatype;</code>
C. <code>datatype = variable_name;</code>
D. <code>variable_name = datatype;</code>

Q. What is the purpose of declaring a variable?

A. To reserve memory space
B. To give a name to a memory location
C. To specify the data type of the value to be stored
D. All of the above

Q. What is variable initialization in C?

A. Assigning a value to a variable when it is declared
B. Declaring a variable without assigning a value
C. Specifying the data type of a variable
D. Giving a name to a variable

Q. What is the difference between declaration and definition of a variable?

A. Declaration specifies the type and name, while definition reserves memory and optionally initializes the variable.
B. Declaration reserves memory, while definition specifies the type and name.
C. There is no difference.
D. Declaration initializes the variable, while definition only reserves memory.

Q. What is the output data type of the following expression? <code>int a = 5, b = 3; float result = a / b;</code>

A. float
B. int
C. double
D. char

Q. What is the output of the following code? <code>int x = 5; int y = ++x; printf("%d %d", x, y);</code>

A. 5 5
B. 6 5
C. 6 6
D. 5 6

Q. What is the output of the following code? <code>int a = 10, b = 5; a = a & b; printf("%d", a);</code>

A. 10
B. 5
C. 0
D. 1

Q. What is the purpose of the <code>const</code> keyword in C?

A. To declare a constant variable
B. To declare a read-only variable
C. To make a variable unchangeable
D. All of the above





Q. What is the output of the following code? <code>const int PI = 3.14; printf("%d", PI);</code>

A. 3.14
B. Error: incompatible types
C. 3
D. 0

Q. How can you declare multiple variables of the same type in a single statement?

A. By separating the variable names with commas
B. By using an array
C. By using a structure
D. By using a pointer

Q. What is the output of the following code? <code>int x = 5; int y = 3; int z = x++ - ++y; printf("%d", z);</code>

A. 1
B. 2
C. 3
D. 4

Q. What is the output of the following code? <code>int a = 10, b = 20; a += b++; printf("%d %d", a, b);</code>

A. 30 20
B. 30 21
C. 20 21
D. 20 20

Q. What will be the output of the following code snippet?

#include <stdio.h>

int main() {
    int num = 5;
    printf("The value of num is: %d", num);
    return 0;
}
A.
The value of num is: 10
B.
The value of num is: 5
C.
Compilation error
D.
Runtime error

Q. Which data type is used to store a single character in C?

A.
int

B.
float

C.
char

D.
double

Q. How can you declare and initialize a variable of type float in C?

A.
float pi = 3.14;

B.
float pi = "3.14"

C.
float = 3.14 pi;

D.
pi = 3.14 float;

Q. What will be the output of the following code snippet?

#include <stdio.h>

int main() {
    int a = 10, b = 20;
    int sum = a + b;
    printf("The sum of a and b is: %d", sum);
    return 0;
}
A.
The sum of a and b is: 30
B.
The sum of a and b is: 20
C.
The sum of a and b is: 10
D.
Compilation error

Q. Which of the following is a valid way to declare and initialize a variable of type double in C?

A.
double pi = 3.14159;

B.
double = 3.14159 pi;

C.
pi = 3.14159 double;

D.
double pi 3.14159;

Q. What will be the output of the following code snippet?

#include <stdio.h>

int main() {
    char letter = 'A';
    printf("The character is: %c", letter);
    return 0;
}
A.
The character is: A
B.
The character is: B
C.
The character is: 65
D.
Compilation error

Q. How can you declare an array of 5 integers in C?

A.
int numbers[5];

B.
int numbers[= 5];

C.
int numbers = [5];

D.
int = numbers[5];

Q. What will be the output of the following code snippet?

#include <stdio.h>

int main() {
    int age = 25;
    age++;
    printf("My age is: %d", age);
    return 0;
}
A.
My age is: 25
B.
My age is: 26
C.
My age is: 27
D.
Compilation error

Q. Which of the following is a valid way to declare and initialize a string variable in C?

A.
char name[] = "John";

B.
char = "John" name[];

C.
"John" = char name[];

D.
char name = "John"

Q. What will be the output of the following code snippet?

#include <stdio.h>

int main() {
    int num = 10;
    num += 5;
    printf("The value of num is: %d", num);
    return 0;
}
A.
The value of num is: 10
B.
The value of num is: 15
C.
The value of num is: 5
D.
Compilation error