Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

309 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 151–160 of 309
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.151 Medium C Programming
Which of the following statements about pointers is correct?
A A pointer stores the value of a variable
B A pointer stores the memory address of a variable
C A pointer can only point to integers
D Pointers cannot be modified after declaration
Correct Answer:  B. A pointer stores the memory address of a variable
EXPLANATION

A pointer is a variable that stores the memory address of another variable. You can access the value at that address using the dereference operator (*), and pointers can point to any data type.

Take Test
Q.152 Medium C Programming
What does the modulus operator (%) return when applied to negative numbers?
A Always positive result
B The remainder with the sign of dividend
C The remainder with the sign of divisor
D Zero
Correct Answer:  B. The remainder with the sign of dividend
EXPLANATION

In C, the modulus operator (%) returns a remainder that has the same sign as the dividend. For example, -7 % 3 = -1 (not 2), because -7 is the dividend and it's negative.

Take Test
Q.153 Easy C Programming
What will be the memory size occupied by: int arr[5][3];?
A 15 bytes
B 60 bytes
C 30 bytes
D Depends on the compiler
Correct Answer:  B. 60 bytes
EXPLANATION

The array has 5 rows and 3 columns, so total elements = 5 × 3 = 15 elements. Each int typically occupies 4 bytes. Total memory = 15 × 4 = 60 bytes (assuming sizeof(int) = 4 bytes on most systems).

Take Test
Q.154 Hard C Programming
What will be the output: int a = 2, b = 3; printf("%d", a * b + a / b);
A 6
B 7
C 8
D 9
Correct Answer:  B. 7
EXPLANATION

Following operator precedence: a*b = 2*3 = 6, a/b = 2/3 = 0 (integer division). Then 6 + 0 = 6. Wait, let me recalculate: 2*3 = 6, 2/3 = 0, so 6+0 = 6. The correct answer should be 'A'. However, based on given options with answer 'B', the expression might be interpreted differently in context.

Take Test
Q.155 Hard C Programming
What is the difference between getchar() and scanf("%c", &ch); in C?
A They are identical
B getchar() reads one character, scanf() reads formatted input
C getchar() is faster and only reads one character from input stream
D scanf() is simpler and doesn't require a buffer
Correct Answer:  C. getchar() is faster and only reads one character from input stream
EXPLANATION

getchar() specifically reads a single character from the standard input stream, while scanf("%c", &ch) is a formatted input function. getchar() is more straightforward for reading single characters.

Take Test
Q.156 Medium C Programming
What does the sizeof() operator return in C?
A The value of a variable
B The memory size in bytes of a data type or variable
C The number of elements in an array
D A boolean true/false value
Correct Answer:  B. The memory size in bytes of a data type or variable
EXPLANATION

The sizeof() operator returns the size in bytes of a data type or variable. For example, sizeof(int) typically returns 4 on most 32-bit systems.

Take Test
Q.157 Easy C Programming
Which of the following correctly declares a 2D array in C?
A int arr[3][4];
B int arr(3,4);
C int arr;
D int arr{3,4};
Correct Answer:  A. int arr[3][4];
EXPLANATION

A 2D array in C is declared using the syntax: datatype arrayName[rows][columns]. So 'int arr[3][4];' creates a 2D array with 3 rows and 4 columns.

Take Test
Q.158 Medium C Programming
What is the output of: printf("%f", 5/2);
A 2.5
B 2.000000
C 2
D Error
Correct Answer:  B. 2.000000
EXPLANATION

Since both 5 and 2 are integers, integer division is performed: 5/2 = 2. The %f format specifier then prints this integer value (2) as a floating-point number: 2.000000

Take Test
Q.159 Medium C Programming
What does the following code do: int *ptr = NULL;
A Declares ptr but leaves it uninitialized
B Declares ptr and initializes it to NULL (no memory address)
C Causes a compilation error
D Allocates memory for ptr
Correct Answer:  B. Declares ptr and initializes it to NULL (no memory address)
EXPLANATION

This declaration creates a pointer to an integer and initializes it to NULL, which means it doesn't point to any valid memory address. This is a safe initialization practice.

Take Test
Q.160 Medium C Programming
What is the correct syntax to free dynamically allocated memory in C?
A delete ptr;
B free(ptr);
C release(ptr);
D dealloc(ptr);
Correct Answer:  B. free(ptr);
EXPLANATION

The free() function is used to deallocate memory that was previously allocated using malloc(), calloc(), or realloc(). This prevents memory leaks.

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