Central Exam — Computer Knowledge
UPSC · SSC · Bank · Railway · NDA — Central Government Exam MCQ Practice
94 Questions 5 Topics Take Test
Advertisement
Showing 1–10 of 94 questions
Q.1 Easy
Which of the following correctly describes the difference between malloc() and calloc() in C?
A malloc() initializes memory to zero, calloc() does not
B calloc() initializes memory to zero and takes two arguments (number of elements and size), malloc() takes one argument and does not initialize
C malloc() is faster than calloc() but uses more memory
D calloc() can only allocate memory for arrays, malloc() can allocate for any data type
Correct Answer:  B. calloc() initializes memory to zero and takes two arguments (number of elements and size), malloc() takes one argument and does not initialize
Explanation:

The answer is correct because it accurately captures the fundamental distinction between these two memory allocation functions in C. malloc() allocates a block of uninitialized memory and requires only the total number of bytes as a single argument, while calloc() allocates memory for an array of elements, takes two arguments (number of elements and size per element), and crucially initializes all allocated memory to zero. This initialization feature of calloc() is a key advantage when you need guaranteed zero values, whereas malloc() leaves memory with whatever garbage values were previously there. Other options would be incorrect if they claimed malloc() initializes memory, if they stated calloc() takes only one argument, or if they reversed which function initializes to zero.

Take Test
Q.2 Easy
Which data structure uses the LIFO (Last In First Out) principle and is commonly used for function call management in programming languages?
A Queue
B Stack
C Heap
D Linked List
Correct Answer:  B. Stack
Explanation:

A Stack follows LIFO principle where the last element inserted is the first one to be removed.

It is fundamental in managing function calls through the call stack, undo/redo operations, and expression evaluation.

Queues use FIFO, Heaps are used for priority ordering, and Linked Lists maintain sequential but flexible storage.

Take Test
Q.3 Easy C Programming
What is the output of the following C code?
int x = 5;
printf("%d", x++);
A 6
B 5
C Compilation error
D Undefined behavior
Correct Answer:  B. 5
Explanation:

The post-increment operator (x++) returns the current value of x before incrementing. So printf prints 5, and then x becomes 6.

Take Test
Q.4 Easy C Programming
Which of the following is the correct syntax to declare a pointer in C?
A int *ptr;
B int& ptr;
C int ^ptr;
D int @ptr;
Correct Answer:  A. int *ptr;
Explanation:

In C, pointers are declared using the asterisk (*) symbol before the variable name. The syntax is 'datatype *pointer_name;'

Take Test
Q.5 Easy C Programming
What will be the size of the following array in bytes?
char arr[10];
A 10 bytes
B 20 bytes
C 40 bytes
D 5 bytes
Correct Answer:  A. 10 bytes
Explanation:

Each char occupies 1 byte in memory. An array of 10 chars will occupy 10 × 1 = 10 bytes.

Take Test
Advertisement
Q.6 Easy C Programming
What is the purpose of the 'void' keyword in C?
A To declare a function that returns nothing
B To declare a generic pointer
C Both A and B
D To declare empty variables
Correct Answer:  C. Both A and B
Explanation:

void is used in two contexts: (1) as a function return type when a function doesn't return a value, and (2) to declare a generic pointer (void *) that can point to any data type.

Take Test
Q.7 Easy C Programming
What is the output of the following C code?
int a = 10, b = 20;
int c = (a > b) ? a : b;
printf("%d", c);
A 10
B 20
C Compilation error
D 30
Correct Answer:  B. 20
Explanation:

The ternary operator (condition ? true_value : false_value) evaluates the condition (a > b). Since 10 is not greater than 20, it returns b which is 20.

Take Test
Q.8 Easy C Programming
What does the strlen() function return?
A Number of characters in a string including null terminator
B Number of characters in a string excluding null terminator
C Size of memory allocated to string
D Address of the first character
Correct Answer:  B. Number of characters in a string excluding null terminator
Explanation:

strlen() returns the length of a string without counting the null terminator ('\0'). For example, strlen("hello") returns 5, not 6.

Take Test
Q.9 Easy C Programming
Which header file is required to use the printf() function in C?
A #include
B #include
C #include
D #include
Correct Answer:  B. #include
Explanation:

The stdio.h header file contains declarations for standard input/output functions like printf() and scanf().

Take Test
Q.10 Easy C Programming
Which of the following is a valid variable name in C?
A 2var
B _variable
C var-name
D var name
Correct Answer:  B. _variable
Explanation:

Variable names in C must start with a letter or underscore, not a digit. _variable is valid. '2var' starts with digit, 'var-name' contains hyphen (invalid), 'var name' contains space (invalid).

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