C and C++ Programming Fundamentals
A comprehensive quiz covering C and C++ programming concepts including pointers, functions, file handling, structures, data structures, and control flow. Tests knowledge from beginner to advanced levels.
Questions
Which of the following functions will produce a value 10 if x = 9.7?
- log
- floor
- abs
- ceil
- round
What will be the output of the above code?
for (;;) {
printf("Hello");
}
- Compilation Error.
- The word 'Hello' will be printed infinitely.
- 'Hello' will be printed only once.
- 'Hello' will not be printed at all.
- 'Hello' will print once and then program will show a runtime error.
Which of the following symbols is used to denote passing of arguments 'by reference'?
- *
- &
- %
- !
- #
Which of the following is NOT a valid statement regarding recursive functions?
- A recursive function is a special function that calls itself.
- A recursive function allows us to break down a complex problem in small parts.
- It must have an exit condition.
- The first function call should be the first one to complete.
- Recursion method is applied in many algorithms such as quick sort or binary sort.
Which of the following functions is used to place the pointer at a particular position in a file?
- seekp()
- rewind()
- ftell()
- fseek()
- fread()
Which of the following statements is FALSE regarding functions in C?
- A function cannot return more than 1 value.
- It is a group of statements that performs a task.
- Functions cannot be defined by the user.
- The return statement is used to return a value from a function.
- A function can call any number of functions.
What are tokens in C?
void main() {
int const* p = 5;
printf("%d", ++(*p));
}
- Collection of values having same data type
- The basic element recognized by the compiler
- The largest individual units of program
- Pointers
- References
What will the output of the strcmp() function if the strings to be compared are exactly the same?
- 0
- 1
- True
- False
- -1
When we declare a pointer to a structure, which of the following operators is used to access the structure variable through the pointer object?
- .(dot)
- * (Asterisk)
- & (Ampersand)
- -> (Arrow)
- # (Hash)
Which of the following statements is FALSE regarding switch case statement?
- We can have any number of case statements within a switch.
- When a break statement is reached, the switch terminates.
- Using default in switch case is optional.
- The value to be compared can be of any type.
- Every case need not have a break statement.
Which of the following file modes opens the file in such a way that all the new data is added to the end of file and we can perform reading operations also?
- w
- a
- a+
- +a
- w+
What is a Dequeue?
- It is the same as queue.
- Elements can be added from the top only.
- Elements can only be removed from the front and added from the rear.
- Elements can only be added from the front and removed from rear.
- Elements can be added to or removed from either the front or rear.
Which of the following keywords is used to change the name of an inbuilt datatype during compilation?
- #define
- rename
- typedef
- #pragma
- const
What is the use of the perror() function in C?
- Prints the error message specified by the compiler.
- Works same as printf().
- Prints the garbage value assigned by the compiler.
- Works same as the gets() method.
- None of the above
Which of the following statements is FALSE regarding structures?
- Structures are user defined data types.
- Structures cannot be nested.
- Structures can contain different types of variables.
- Structures are used to represent a record.
- The dot operator is used to access the structure members.
Which of the following is NOT an operator in C?
- sizeof
- !
- ~
- | |
- scope resoultion operator (: :)
void main() {
int i = 4, x;
x = ++i + ++i + ++i;
printf("%d", x);
}
What will be the output of the above code?
- 20
- 21
- 18
- 19
- 22
Which of the following data structures stores the data in FIFO mode?
- LinkedList
- Binary Tree
- Stack
- Queue
- Array
Which of the following functions is used to release the allocated memory which is no longer required?
- dealloc()
- delete()
- free()
- realloc()
- clear()
Which of the following is NOT a valid sorting method?
- Insertion sort
- Selection sort
- Bubble sort
- Merge Sort
- Deep Sort
Which of the following tree traversal methods have the order as - root , left, right?
- Preorder
- Linear
- Level Order
- Inorder
- Postorder
Which of the following format specifiers is used to process unsigned hexadecimal values?
- %x
- %d
- %o
- %u
- %e
int main() {
float x = fun(2, 3);
printf("%f", x);
}
int fun(int x, float y) // Line 7
{
x = 20.9; //Line 9
return x;
}
What will be the output of the above code?
- 20.99
- 20.00
- No output
- Error
- 20
The default parameter passing mechanism is called __________.
- call by value
- call by name
- call by reference
- call by address
- call by default
Which of the following statements is TRUE regarding the 'switch' statement?
- continue can be used but break cannot be used
- continue cannot be used but break can be used
- Both continue and break can be used
- Neither continue nor break can be used
- We cannot use switch statement in nested form