c mcq objectives questions answers

C Mcqs questions

1. Who is the father of C language ?

a. James Gosling
b. Dennis Ritchie
c. Rasmus Lerdorf
d. Steve Jobs

Show Answer

The correct option is (b)
Explanation:
Dennis Ritchie is the father of C Programming Language. C programming language was developed in 1972 at American Telephone & Telegraph Bell Laboratories of USA.

2. All keywords in C are in ____________?

a. UpperCase letters
b. CamelCase letters
c. LowerCase letters
d. None of the above

Show Answer

The correct option is (c)
Explanation:
None

3. Which is valid C expression ?

a. int $numeric_num = 10000;
b. int my numeric= 1000;
c. int numeric_num = 100000;
d. int numeric_num = 100,000;

Show Answer

The correct option is (c)
Explanation:
Space, comma and $ cannot be used in a variable name.

4. What is short int in C programming ?

a. The basic data type of C
b. Short is the qualifier and int is the basic data type
c. Qualifier
d. All of above

Show Answer

The correct option is b
Explanation: None

5. What is the output of the following program ?

int main()
{
int a = 3, b = 5;
int t = a;
a = b;
b = t;
printf(“%d %d”, a, b);
return 0;
}

a) 3 5
b) 3 3
c) 5 5
d) 5 3

Show Answer

Correct Option : d
Explanation:
The above code snippet swaps 2 numbers in C.

6. How is an array initialized in C language??

a) int a[3] = {1, 2, 3};
b) int a[] = new int[3] c) int a(3) = [1, 2, 3] d) int a = {1, 2, 3};

Show Answer

correct option a
Explanation:
The correct way of initialization of an array is given in Option a.

7. What is the output of the following code snippet?

int main()
{
int a[] = {1, 2, 3, 4};
int sum = 0;
for(int i = 0; i < 4; i++) {
sum += a[i];
}
printf(“%d”, sum);
return 0;
}

a. 1
b. 4
c. 10
d. 20

Show Answer

correct option C
Explanation:
The code basically calculates the sum of all the elements in the array a[].

8. How is the 3rd element in an array accessed based on pointer notation?

a) *(a + 3)
b) *a + 3
c) *(*a + 3)
d) &(a + 3)

Show Answer

correct option a
Explanation:
a[3] is equivalent to *(a + 3) in pointer notation.

9. What is the output of the following code snippet?

void solve() {
int first = 10, second = 20;
int third = first + second;
{
int third = second – first;
printf(“%d “, third);
}
printf(“%d”, third);
}
int main()
{
solve();
return 0;
}

a. 30 10
b. 10 20
c. 20 10
d. 10 30

Show Answer

correct option d
Explanation:
This problem uses the concept of scopes. In the pair of {}, the variable third which is declared inside it is local to the block and takes preference over the global third. So it is printed first, and then the global third.

10. What is the output of the following code snippet?

void solve() {
int a = 3;
int res = a++ + ++a + a++ + ++a;
printf(“%d”, res);
int main()
{
solve();
return 0;
}

a. 20
b. 12
c. 24
d. 18

Show Answer

correct option a
Explanation:
The ++a operator follows the “change then use” rule. The a++ operator follows the “use then change” rule. Using these rules along with proper associativity we get the result of 20.