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.

25 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following functions will produce a value 10 if x = 9.7?

  1. log
  2. floor
  3. abs
  4. ceil
  5. round
Question 2 Multiple Choice (Single Answer)

What will be the output of the above code?

for (;;) {
  printf("Hello");
}
  1. Compilation Error.
  2. The word 'Hello' will be printed infinitely.
  3. 'Hello' will be printed only once.
  4. 'Hello' will not be printed at all.
  5. 'Hello' will print once and then program will show a runtime error.
Question 3 Multiple Choice (Single Answer)

Which of the following symbols is used to denote passing of arguments 'by reference'?

  1. *
  2. &
  3. %
  4. !
  5. #
Question 4 Multiple Choice (Single Answer)

Which of the following is NOT a valid statement regarding recursive functions?

  1. A recursive function is a special function that calls itself.
  2. A recursive function allows us to break down a complex problem in small parts.
  3. It must have an exit condition.
  4. The first function call should be the first one to complete.
  5. Recursion method is applied in many algorithms such as quick sort or binary sort.
Question 5 Multiple Choice (Single Answer)

Which of the following functions is used to place the pointer at a particular position in a file?

  1. seekp()
  2. rewind()
  3. ftell()
  4. fseek()
  5. fread()
Question 6 Multiple Choice (Single Answer)

Which of the following statements is FALSE regarding functions in C?

  1. A function cannot return more than 1 value.
  2. It is a group of statements that performs a task.
  3. Functions cannot be defined by the user.
  4. The return statement is used to return a value from a function.
  5. A function can call any number of functions.
Question 7 Multiple Choice (Single Answer)

What are tokens in C?

void main() {
  int const* p = 5;
  printf("%d", ++(*p));
}
  1. Collection of values having same data type
  2. The basic element recognized by the compiler
  3. The largest individual units of program
  4. Pointers
  5. References
Question 8 Multiple Choice (Single Answer)

What will the output of the strcmp() function if the strings to be compared are exactly the same?

  1. 0
  2. 1
  3. True
  4. False
  5. -1
Question 9 Multiple Choice (Single Answer)

When we declare a pointer to a structure, which of the following operators is used to access the structure variable through the pointer object?

  1. .(dot)
  2. * (Asterisk)
  3. & (Ampersand)
  4. -> (Arrow)
  5. # (Hash)
Question 10 Multiple Choice (Single Answer)

Which of the following statements is FALSE regarding switch case statement?

  1. We can have any number of case statements within a switch.
  2. When a break statement is reached, the switch terminates.
  3. Using default in switch case is optional.
  4. The value to be compared can be of any type.
  5. Every case need not have a break statement.
Question 11 Multiple Choice (Single Answer)

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?

  1. w
  2. a
  3. a+
  4. +a
  5. w+
Question 12 Multiple Choice (Single Answer)

What is a Dequeue?

  1. It is the same as queue.
  2. Elements can be added from the top only.
  3. Elements can only be removed from the front and added from the rear.
  4. Elements can only be added from the front and removed from rear.
  5. Elements can be added to or removed from either the front or rear.
Question 13 Multiple Choice (Single Answer)

Which of the following keywords is used to change the name of an inbuilt datatype during compilation?

  1. #define
  2. rename
  3. typedef
  4. #pragma
  5. const
Question 14 Multiple Choice (Single Answer)

What is the use of the perror() function in C?

  1. Prints the error message specified by the compiler.
  2. Works same as printf().
  3. Prints the garbage value assigned by the compiler.
  4. Works same as the gets() method.
  5. None of the above
Question 15 Multiple Choice (Single Answer)

Which of the following statements is FALSE regarding structures?

  1. Structures are user defined data types.
  2. Structures cannot be nested.
  3. Structures can contain different types of variables.
  4. Structures are used to represent a record.
  5. The dot operator is used to access the structure members.
Question 16 Multiple Choice (Single Answer)

Which of the following is NOT an operator in C?

  1. sizeof
  2. !
  3. ~
  4. | |
  5. scope resoultion operator (: :)
Question 17 Multiple Choice (Single Answer)
void main() {
  int i = 4, x;
  x = ++i + ++i + ++i;
  printf("%d", x);
}

What will be the output of the above code?

  1. 20
  2. 21
  3. 18
  4. 19
  5. 22
Question 18 Multiple Choice (Single Answer)

Which of the following data structures stores the data in FIFO mode?

  1. LinkedList
  2. Binary Tree
  3. Stack
  4. Queue
  5. Array
Question 19 Multiple Choice (Single Answer)

Which of the following functions is used to release the allocated memory which is no longer required?

  1. dealloc()
  2. delete()
  3. free()
  4. realloc()
  5. clear()
Question 20 Multiple Choice (Single Answer)

Which of the following is NOT a valid sorting method?

  1. Insertion sort
  2. Selection sort
  3. Bubble sort
  4. Merge Sort
  5. Deep Sort
Question 21 Multiple Choice (Single Answer)

Which of the following tree traversal methods have the order as - root , left, right?

  1. Preorder
  2. Linear
  3. Level Order
  4. Inorder
  5. Postorder
Question 22 Multiple Choice (Single Answer)

Which of the following format specifiers is used to process unsigned hexadecimal values?

  1. %x
  2. %d
  3. %o
  4. %u
  5. %e
Question 23 Multiple Choice (Single Answer)
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?

  1. 20.99
  2. 20.00
  3. No output
  4. Error
  5. 20
Question 24 Multiple Choice (Single Answer)

The default parameter passing mechanism is called __________.

  1. call by value
  2. call by name
  3. call by reference
  4. call by address
  5. call by default
Question 25 Multiple Choice (Single Answer)

Which of the following statements is TRUE regarding the 'switch' statement?

  1. continue can be used but break cannot be used
  2. continue cannot be used but break can be used
  3. Both continue and break can be used
  4. Neither continue nor break can be used
  5. We cannot use switch statement in nested form