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 111–120 of 200
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.111 Medium C Programming
What is the return type of the malloc() function?
A int
B void*
C char*
D null
Correct Answer:  B. void*
EXPLANATION

malloc() returns a void pointer (void*) which can be cast to any pointer type. It returns NULL if memory allocation fails.

Take Test
Q.112 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.

Take Test
Q.113 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.

Take Test
Q.114 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.

Take Test
Q.115 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.

Take Test
Q.116 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.

Take Test
Q.117 Hard C Programming
What will be the output of: int a = 5; int *p = &a; printf("%d %d", a, *p);?
A 5 garbage value
B 5 5
C address address
D 0 5
Correct Answer:  B. 5 5
EXPLANATION

p is a pointer storing the address of a. *p (dereferencing) gives the value at that address, which is 5. So both a and *p print 5.

Take Test
Q.118 Hard C Programming
In C, when passing arrays to functions, what is actually passed?
A A copy of all array elements
B The address of the first element (pointer)
C The array size
D All array elements and size
Correct Answer:  B. The address of the first element (pointer)
EXPLANATION

When an array is passed to a function in C, it decays to a pointer pointing to the first element. This is why changes made in the function affect the original array.

Take Test
Q.119 Medium C Programming
What is the output of the following program: int x = 5; if(x > 3) printf("Greater"); else printf("Smaller");?
A Smaller
B Greater
C 5
D Error
Correct Answer:  B. Greater
EXPLANATION

x=5 is greater than 3, so the condition (x > 3) evaluates to true. The if block executes, printing 'Greater'.

Take Test
Q.120 Medium C Programming
Which of the following is the correct way to define a function that takes no parameters and returns no value?
A void function() { }
B null function() { }
C empty function() { }
D void function(void) { }
Correct Answer:  A. void function() { }
EXPLANATION

In C, void function() { } is correct. In some contexts, void function(void) { } is more explicit. Options B and C use invalid keywords for this purpose.

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