Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

94 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 91–94 of 94
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.91 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;'

Test
Q.92 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.

Test
Q.93 Easy Data Structures
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.

Test
Q.94 Easy C Programming
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.

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