Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

200 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 200
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.31 Medium C Programming
In the expression: int arr[10]; what is arr[5]?
A A pointer to the 5th element
B The value at memory address arr + 5
C Both A and B are equivalent
D An integer value between 0-10
Correct Answer:  C. Both A and B are equivalent
EXPLANATION

arr[5] accesses the element at index 5, which is at memory address (arr + 5). Array name arr acts as a pointer to the first element.

Take Test
Q.32 Medium C Programming
What is the return type of malloc() function?
A int*
B char*
C void*
D size_t
Correct Answer:  C. void*
EXPLANATION

malloc() returns a void pointer (void*), which can be cast to any data type pointer as needed by the programmer.

Take Test
Q.33 Medium C Programming
What is the purpose of the const keyword when used with a pointer?
A To make the pointer variable unchangeable
B To make the pointed data unchangeable
C Both A and B depending on placement
D To allocate memory in the constant segment
Correct Answer:  C. Both A and B depending on placement
EXPLANATION

const int *ptr makes the data constant (const int * ptr). int * const ptr makes the pointer constant. The position of const matters.

Take Test
Q.34 Medium C Programming
Which of the following correctly uses the ternary operator?
A x = (a > b) : a : b;
B x = (a > b) ? a : b;
C x = a > b ? a : b
D x = (a > b) -> a : b;
Correct Answer:  B. x = (a > b) ? a : b;
EXPLANATION

The ternary operator syntax is: condition ? value_if_true : value_if_false. Option B is the only correctly formatted statement.

Take Test
Q.35 Medium C Programming
What will be printed by: int x = 5; printf("%d", ++x + x++);?
A 11
B 12
C 13
D 14
Correct Answer:  B. 12
EXPLANATION

++x increments x to 6 (pre-increment), then x++ returns 6 and increments x to 7. So: 6 + 6 = 12. Post-increment returns the old value.

Take Test
Q.36 Medium C Programming
What is the correct syntax to pass a 2D array to a function in C?
A func(int arr[][])
B func(int arr[rows][cols])
C func(int arr[][cols])
D func(int **arr)
Correct Answer:  C. func(int arr[][cols])
EXPLANATION

When passing a 2D array to a function, the number of columns must be specified, but the number of rows is optional. Option C is the standard correct syntax.

Take Test
Q.37 Easy C Programming
What keyword is used to create a pointer variable in C?
A ref
B *
C &
D ptr
Correct Answer:  B. *
EXPLANATION

The asterisk (*) symbol is used to declare pointer variables. For example: int *ptr; declares a pointer to an integer.

Take Test
Q.38 Easy C Programming
What will be the output of: printf("%d", 5 + 3 * 2);?
A 16
B 11
C 13
D 18
Correct Answer:  B. 11
EXPLANATION

Operator precedence: multiplication (*) is performed before addition (+). So: 3 * 2 = 6, then 5 + 6 = 11.

Take Test
Q.39 Easy C Programming
Which of the following is NOT a valid variable name in C?
A _myVar
B myVar123
C 123myVar
D my_var
Correct Answer:  C. 123myVar
EXPLANATION

Variable names in C cannot start with a digit. They must begin with a letter (a-z, A-Z) or underscore (_). '123myVar' is invalid.

Take Test
Q.40 Hard C Programming
Which of the following is the correct way to declare a pointer to a function that returns an int and takes two int parameters?
A int *ptr(int, int);
B int (*ptr)(int, int);
C int *ptr[int, int];
D int ptr*(int, int);
Correct Answer:  B. int (*ptr)(int, int);
EXPLANATION

The correct syntax for a function pointer is: int (*ptr)(int, int);. The parentheses around (*ptr) are necessary to indicate that ptr is a pointer to a function, not a function returning a pointer. Option A declares a function returning an int pointer.

Take Test
IGET
iget AI
Online · Ask anything about exams
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