Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

60 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 60
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.31 Easy C Programming
Which of the following is a correct way to initialize a 1D array in C?
A int arr[5] = {1, 2, 3, 4, 5};
B int arr[] = {1, 2, 3, 4, 5};
C int arr[5];
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

All three methods are valid. Option A initializes with size 5, option B auto-determines size from initialization, and option C declares without initialization.

Test
Q.32 Easy C Programming
What does the sizeof() operator return?
A The address of a variable
B The number of bytes occupied by a data type or variable
C The maximum value a variable can hold
D The number of bits in a variable
Correct Answer:  B. The number of bytes occupied by a data type or variable
EXPLANATION

sizeof() is a unary operator that returns the number of bytes occupied by a variable or data type in memory.

Test
Q.33 Easy C Programming
Which operator is used to access the value at an address in C?
A &
B *
C ->
D .
Correct Answer:  B. *
EXPLANATION

The * operator is the dereference operator that accesses the value at a memory address. The & operator gets the address of a variable.

Test
Q.34 Easy C Programming
What is the correct syntax to declare a constant in C?
A const int x = 10;
B int const x = 10;
C constant int x = 10;
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

Both 'const int x = 10;' and 'int const x = 10;' are valid ways to declare constants in C. The const keyword can appear before or after the type.

Test
Q.35 Easy C Programming
Which header file is required for using the printf() function?
A cstdlib.h
B stdio.h
C string.h
D math.h
Correct Answer:  B. stdio.h
EXPLANATION

stdio.h (Standard Input/Output header) contains declarations for printf(), scanf(), and other I/O functions.

Test
Q.36 Easy C Programming
What is the purpose of the return statement in a C function?
A To exit the program
B To return a value to the caller and exit the function
C To declare variables
D To create a loop
Correct Answer:  B. To return a value to the caller and exit the function
EXPLANATION

The return statement is used to exit a function and return a value (if any) to the calling function. If the function has return type void, no value is returned.

Test
Q.37 Easy C Programming
Which of the following is used to declare a constant in C?
A constant int x = 5;
B const int x = 5;
C final int x = 5;
D immutable int x = 5;
Correct Answer:  B. const int x = 5;
EXPLANATION

In C, the 'const' keyword is used to declare constants. Once a const variable is initialized, its value cannot be changed. Options A, C, and D are not valid C syntax.

Test
Q.38 Easy C Programming
What will be the output of: int a = 10; int b = 20; int c = a + b; printf("%d", c);?
A 10
B 30
C 20
D Error
Correct Answer:  B. 30
EXPLANATION

Variable 'a' is initialized to 10, 'b' is initialized to 20. When c = a + b, c becomes 10 + 20 = 30. Therefore, printf outputs 30.

Test
Q.39 Easy C Programming
In C programming, which of the following is NOT a valid data type?
A int
B float
C string
D double
Correct Answer:  C. string
EXPLANATION

In C, 'string' is not a primitive data type. C uses 'char' arrays to represent strings. The valid primitive data types are int, float, double, char, void, and their variants.

Test
Q.40 Easy C Programming
What is the purpose of the break statement in a loop?
A Pause the loop temporarily
B Exit the loop immediately
C Restart the loop
D Skip the current iteration
Correct Answer:  B. Exit the loop immediately
EXPLANATION

The break statement exits or terminates the current loop immediately. Option D describes continue (which skips to next iteration), while break actually exits the loop.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips