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 251–260 of 499
Topics in C Programming
Q.251 Medium Pointers
What is the output?
int a = 5;
int *p = &a;
int **q = &p;
printf("%d", **q);
A 5
B Address of a
C Address of p
D Compilation error
Correct Answer:  A. 5
EXPLANATION

q is a pointer to pointer p. **q dereferences q to get p, then dereferences p to get the value 5.

Take Test
Q.252 Medium Arrays & Strings
For char arr[5] = {'a', 'b', 'c', 'd', 'e'}, is this a valid string?
A Yes, always valid
B No, missing null terminator
C Only if last element is '\0'
D Depends on compiler
Correct Answer:  B. No, missing null terminator
EXPLANATION

String functions expect null terminator. This array has no '\0', so it's a character array but NOT a proper string for str* functions.

Take Test
Q.253 Medium Arrays & Strings
What is the correct syntax to pass a 2D array to a function?
A void func(int arr[][])
B void func(int arr[3][4])
C void func(int **arr)
D Any of the above
Correct Answer:  B. void func(int arr[3][4])
EXPLANATION

First dimension can be omitted, but second must be specified: int arr[][4]. Option C (int **arr) is not equivalent - it's pointer to pointer.

Take Test
Q.254 Medium Arrays & Strings
What is the output of: char str[20]; scanf("%s", str); when input is 'Hello World'?
A Entire 'Hello World' is stored
B Only 'Hello' is stored (stops at whitespace)
C Compilation error
D Buffer overflow occurs
Correct Answer:  B. Only 'Hello' is stored (stops at whitespace)
EXPLANATION

%s format specifier stops reading at whitespace. To read entire line including spaces, use fgets() or %[^\n].

Take Test
Q.255 Medium Arrays & Strings
In a string with escape sequences like "Hello\nWorld", how many characters are counted by strlen()?
A 10
B 11
C 12
D 13
Correct Answer:  B. 11
EXPLANATION

\n is a single character (newline). 'Hello' = 5 + \n = 1 + 'World' = 5, total = 11 characters (not counting null terminator).

Take Test
Q.256 Medium Arrays & Strings
Which of the following operations is NOT allowed on array names in C?
A arr[0] (indexing)
B arr++ (incrementing)
C sizeof(arr) (size calculation)
D &arr (address of)
Correct Answer:  B. arr++ (incrementing)
EXPLANATION

Array names are non-modifiable lvalues. You cannot use ++ on them. However, individual elements can be accessed and modified.

Take Test
Q.257 Medium Arrays & Strings
What does the expression *(arr + 3) represent for an integer array?
A Address of 4th element
B Value of 4th element (0-indexed as arr[3])
C Size of array plus 3
D Third pointer in array
Correct Answer:  B. Value of 4th element (0-indexed as arr[3])
EXPLANATION

arr + 3 points to the 4th element (0-indexed). Dereferencing with * gives its value, equivalent to arr[3].

Take Test
Q.258 Medium Arrays & Strings
In C, what happens when you pass an array to a function?
A The entire array is copied to function stack
B Only the array name (pointer to first element) is passed
C A deep copy is created
D The array is passed by reference automatically
Correct Answer:  B. Only the array name (pointer to first element) is passed
EXPLANATION

Arrays decay to pointers when passed to functions. Only the address of the first element is passed, not a copy of entire array.

Take Test
Q.259 Medium Arrays & Strings
Which function is safe to use for string concatenation with size limiting?
A strcat()
B strncat()
C concat()
D appendstr()
Correct Answer:  B. strncat()
EXPLANATION

strncat() allows specifying maximum characters to concatenate, preventing buffer overflow. strcat() has no size limit.

Take Test
Q.260 Medium Arrays & Strings
What is the output of printf("%d", sizeof(arr)) for char arr[100]?
A 100
B 1
C 4 or 8 (depending on pointer size)
D 101 (including null terminator)
Correct Answer:  A. 100
EXPLANATION

sizeof(arr) returns the total size of the array in bytes. For char arr[100], it returns 100 bytes regardless of content.

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