Syntax Quiz - Languages C
Free practice quiz: Syntax (Languages C). 54 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 54 questions freeSample questions
In C programming, which of the following is a valid way to declare an integer variable named 'count' and initialize it to 10?
- int count = 10;
- count int = 10;
- declare int count = 10;
- int count := 10;
Show answer
Answer: A. int count = 10;
In C, the syntax for declaring an integer variable is 'int variable_name;'. Initialization can be done directly during declaration using the assignment operator '=', as in 'int variable_name = value;'. Option 'b' has incorrect keyword order, 'c' uses a non-existent 'declare' keyword, and 'd' uses a syntax not valid in C.
What is the correct syntax for accessing an element of an array named 'arr' at index 5 in C?
- arr(5)
- arr[5]
- arr.5
- arr{5}
Show answer
Answer: B. arr[5]
In C, array elements are accessed using square brackets `[]` and the index of the element. Indices are zero-based, so `arr[5]` accesses the sixth element.
Which C statement is used to terminate the execution of a loop prematurely?
- continue
- return
- exit
- break
Show answer
Answer: D. break
The `break` statement is used to exit a loop (`for`, `while`, `do-while`) or a `switch` statement immediately. `continue` skips the rest of the current loop iteration and proceeds to the next. `return` exits a function, and `exit` terminates the entire program.
Which C operator is used for bitwise OR operation?
- &
- &&
- |
- ||
Show answer
Answer: C. |
The single pipe symbol `|` is the bitwise OR operator in C. It performs an OR operation on each corresponding bit of its two operands. `||` is the logical OR operator.
Which C keyword is used to explicitly return a value from a function?
- void
- return
- exit
- break
Show answer
Answer: B. return
The `return` keyword is used to exit a function and optionally pass a value back to the caller. If a function is declared to return `void`, it should not use `return` with a value.