Computer Knowledge
Aptitude · Reasoning · English · CS — Corporate & Campus Interview Prep
65 Questions 5 Topics Take Test
Advertisement
Showing 11–20 of 65 questions
Q.11 Hard C Programming
What is the time complexity of searching for an element in an unsorted array using linear search?
A O(1)
B O(log n)
C O(n)
D O(n²)
Correct Answer:  C. O(n)
Explanation:

Linear search checks each element sequentially. In the worst case, it needs to check all n elements, resulting in O(n) time complexity.

Take Test
Q.12 Hard C Programming
What will be the result of executing: int a = 5, b = 10; int *ptr = &a; ptr = &b; printf("%d", *ptr);?
A 5
B 10
C Address of b
D Compilation error
Correct Answer:  B. 10
Explanation:

ptr is reassigned to point to b. When we dereference ptr using *ptr, we get the value stored at b, which is 10.

Take Test
Q.13 Hard C Programming
Which of the following statements about static variables is TRUE?
A Static variables are re-initialized every function call
B Static variables retain their value between function calls
C Static variables cannot be used in functions
D Static variables are automatically deallocated
Correct Answer:  B. Static variables retain their value between function calls
Explanation:

Static variables are initialized only once and retain their value throughout the program execution. Their value persists between function calls.

Take Test
Q.14 Hard C Programming
What happens when you try to access an array element beyond its size in C?
A Compilation error
B Runtime error with exception
C Undefined behavior
D Returns 0 automatically
Correct Answer:  C. Undefined behavior
Explanation:

C does not perform bounds checking on arrays. Accessing beyond array bounds results in undefined behavior - it may access garbage values, crash, or seem to work without error. This is a common source of bugs.

Take Test
Q.15 Hard C Programming
Which of the following is the correct way to pass a string to a function in C?
A void func(string s);
B void func(char s[]);
C void func(char *s);
D Both B and C
Correct Answer:  D. Both B and C
Explanation:

Both char s[] (array notation) and char *s (pointer notation) are valid ways to pass strings to functions in C. C does not have a built-in string type; strings are represented as character arrays or pointers to char.

Take Test
Advertisement
Q.16 Hard C Programming
Which of the following is an invalid identifier in C?
A myVar
B my_var
C my$var
D _myVar
Correct Answer:  C. my$var
Explanation:

In C, identifiers can only contain alphanumeric characters (a-z, A-Z, 0-9) and underscores (_), and must start with a letter or underscore. The dollar sign (\() is not allowed, making 'my\)var' invalid.

Take Test
Q.17 Hard C Programming
What will be the output of: int x = 5; printf("%d %d", x++, ++x);?
A 5 7
B 6 7
C 5 6
D 6 6
Correct Answer:  A. 5 7
Explanation:

x++ is post-increment (returns 5, then x becomes 6), ++x is pre-increment (x becomes 7, then returns 7). The order of evaluation in printf is implementation-dependent, but typically right to left, giving 5 7.

Take Test
Q.18 Hard C Programming
What is the difference between structure and union in C?
A Both allocate memory to all members simultaneously
B Structure allocates memory to all members; union allocates shared memory
C Union allocates memory to all members; structure allocates shared memory
D No difference
Correct Answer:  B. Structure allocates memory to all members; union allocates shared memory
Explanation:

Structure allocates separate memory for each member (total size = sum of all members). Union shares a single memory location among all members (total size = size of largest member). This is a fundamental difference in memory allocation.

Take Test
Q.19 Hard C Programming
Which of the following function declarations is correct for a function that takes no parameters and returns no value?
A void function(void);
B void function();
C null function(void);
D void function(null);
Correct Answer:  A. void function(void);
Explanation:

The correct syntax is 'void function(void);' where 'void' in parentheses explicitly states no parameters. Option B is also valid in C (defaults to no parameters), but option A is more explicit and portable across C standards.

Take Test
Q.20 Hard C Programming
In C, what is the purpose of the typedef keyword?
A Define a new data type
B Create an alias for existing data types
C Declare type of variables
D Convert one data type to another
Correct Answer:  B. Create an alias for existing data types
Explanation:

typedef creates an alias (synonym) for existing data types. For example, 'typedef int Integer;' creates 'Integer' as an alias for 'int'. This improves code readability and portability. It doesn't create entirely new types, but provides alternative names.

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