Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 261–270 of 499
Topics in C Programming
Q.261 Medium Arrays & Strings
What is the memory layout of a 2D array int arr[3][4] in C?
A Random arrangement in memory
B Row-major order - sequential rows stored consecutively
C Column-major order - sequential columns stored consecutively
D Scattered across memory with pointers
Correct Answer:  B. Row-major order - sequential rows stored consecutively
EXPLANATION

C uses row-major order. The entire array is contiguous in memory with all of row 0, then row 1, then row 2, etc.

Take Test
Q.262 Medium Arrays & Strings
In a string comparison, strcmp('Apple', 'apple') returns:
A 0 (equal)
B A non-zero negative value
C A non-zero positive value
D Compilation error
Correct Answer:  C. A non-zero positive value
EXPLANATION

strcmp() is case-sensitive. ASCII value of 'A' (65) is less than 'a' (97), so it returns negative value. But 'A' < 'a', so it returns -32 (negative).

Take Test
Q.263 Medium Arrays & Strings
What does strcpy(dest, src) do, and what is its main risk?
A Copies src to dest; risk is slow performance
B Copies src to dest; risk is buffer overflow if dest is too small
C Creates a new string; risk is memory leak
D Compares two strings; no risk
Correct Answer:  B. Copies src to dest; risk is buffer overflow if dest is too small
EXPLANATION

strcpy() doesn't check destination buffer size, potentially causing buffer overflow. Modern alternatives include strncpy() or strcpy_s().

Take Test
Q.264 Medium Arrays & Strings
What is the difference between char str[20] and char *str in C?
A No difference, both represent strings
B First is array allocation, second is pointer declaration requiring separate allocation
C First is dynamic, second is static
D Second can hold longer strings
Correct Answer:  B. First is array allocation, second is pointer declaration requiring separate allocation
EXPLANATION

char str[20] allocates 20 bytes on stack. char *str only declares a pointer and requires separate memory allocation (malloc/static string).

Take Test
Q.265 Medium Arrays & Strings
What will be the result of accessing arr[10] when arr is declared as int arr[5]?
A Compilation error
B Runtime error
C Undefined behavior - may access memory beyond array
D Returns 0 by default
Correct Answer:  C. Undefined behavior - may access memory beyond array
EXPLANATION

C doesn't perform bounds checking. Accessing out-of-bounds memory causes undefined behavior and is a common source of bugs.

Take Test
Q.266 Medium Arrays & Strings
Consider a 3D array: int arr[2][3][4]. How many elements total?
A 9 elements
B 24 elements
C 12 elements
D 6 elements
Correct Answer:  B. 24 elements
EXPLANATION

Total elements = 2 × 3 × 4 = 24 elements in the 3D array.

Take Test
Q.267 Medium Arrays & Strings
What is the output?
char str[6] = {'H','e','l','l','o'};
printf("%s", str);
A Hello
B Helo
C Garbage output
D Compilation error
Correct Answer:  C. Garbage output
EXPLANATION

The array has 5 characters but is not null-terminated. printf("%s") will read beyond the array, printing garbage.

Take Test
Q.268 Medium Arrays & Strings
Which statement about 2D arrays in C is correct?
A int arr[3][4] requires 12 contiguous bytes
B arr[0] returns the address of the first row
C arr[0][0] and *(*arr) access the same element
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

arr[0] points to the first row (array of 4 ints). arr[0][0] and *(*arr) both access the first element through pointer dereferencing.

Take Test
Q.269 Medium Arrays & Strings
What is the difference between arr[5] and *arr when arr is an array?
A No difference, both access the same element
B arr[5] accesses 6th element, *arr accesses 1st element
C arr[5] is address, *arr is value
D No valid comparison
Correct Answer:  B. arr[5] accesses 6th element, *arr accesses 1st element
EXPLANATION

arr[5] accesses the element at index 5 (6th element), while *arr (equivalent to arr[0]) accesses the first element.

Take Test
Q.270 Medium Arrays & Strings
What will be printed?
char str[] = "Hello";
printf("%c", *(str+2));
A H
B e
C l
D Compilation error
Correct Answer:  C. l
EXPLANATION

str+2 points to the 3rd character (index 2). *(str+2) dereferences it, printing 'l'.

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