Podcast
Questions and Answers
What is the purpose of the & operator in C?
What is the purpose of the & operator in C?
- Bitwise AND
- Address of operator (correct)
- Pointer to operator
- Bitwise OR
Which of the following is the correct way to access the fourth element of an array named nums?
Which of the following is the correct way to access the fourth element of an array named nums?
- nums.4
- nums(4)
- nums{4}
- nums (correct)
What is the output of the following code?
int i = 0; for (; i < 5; i++) { printf("%d ", i); }
What is the output of the following code?
int i = 0; for (; i < 5; i++) { printf("%d ", i); }
- Infinite loop
- 1 2 3 4
- 0 1 2 3 (correct)
- 0 1 2 3 4
Which of the following statements is true about the do-while loop in C?
Which of the following statements is true about the do-while loop in C?
What is the correct way to define a function in C that returns an integer and takes two parameters a and b?
What is the correct way to define a function in C that returns an integer and takes two parameters a and b?
Which of the following is NOT a valid way to declare a string in C?
Which of the following is NOT a valid way to declare a string in C?
Which of the following is NOT a valid C variable name?
Which of the following is NOT a valid C variable name?
What does the sizeof() operator return in C?
What does the sizeof() operator return in C?
What does the scanf() function do in C?
What does the scanf() function do in C?
What is the result of the expression 3 / 2 in C?
What is the result of the expression 3 / 2 in C?
Which of the following is a logical operator in C?
Which of the following is a logical operator in C?
What is the correct way to declare a constant in C?
What is the correct way to declare a constant in C?
Study Notes
C Variable Names
myVariable
andvariable123
are valid variable names123variable
is not a valid variable name (numbers cannot start a variable name)_variable
is a valid variable name
C Output
printf("%d", x++);
outputs5
(post-incrementx++
returns the original value ofx
)
Declaring Constants in C
const int CONSTANT = 10;
is the correct way to declare a constant in C
sizeof() Operator
- The
sizeof()
operator returns the size of a type or variable in bytes
Division in C
- The result of the expression
3 / 2
in C is1
(integer division truncates the decimal part)
Logical Operators in C
||
is a logical operator in C (logical OR)
Array Declaration in C
int array[10];
is the syntax to declare an array in C with 10 elements
scanf() Function
- The
scanf()
function reads formatted input from the standard input
Terminating a C Program
return 0;
is the correct way to terminate a C program
Conditional Operator
x > y ? x : y
returnsx
ifx
is greater thany
, andy
otherwise
Header Files in C
stdio.h
is the header file required for input and output operations in C
break Statement
- The purpose of the
break
statement in a loop is to terminate the loop
for Loop Syntax
- The correct syntax for the for loop in C is
for (int i = 0; i < 10; i++)
while Loop Output
- The output of the code
while (i < 5) { printf("%d ", i); i += 2; }
is0 2 4
String Declaration in C
char str[] = "Hello";
andchar *str = "Hello";
are valid ways to declare a string in Cchar str = "Hello";
andstring str = "Hello";
are not valid ways to declare a string in C
if Statement
- The output of the code
if (x = 6) printf("True"); else printf("False");
isTrue
(assignmentx = 6
has a non-zero value, which is considered true)
continue Statement
- The purpose of the
continue
statement in a loop is to skip the remaining code in the loop and proceed to the next iteration
Array Access
arr
is a pointer to the first element of the array, soprintf("%d", arr);
prints the memory address of the first element (garbage value)
do-while Loop
- The loop body of a do-while loop is executed at least once before the condition is evaluated
Prefix Increment Operator
- The prefix increment operator
++i
incrementsi
before returning its value, soprintf("%d", ++i);
outputs11
Array Access
nums[3]
is the correct way to access the fourth element of an array namednums
& Operator
- The
&
operator is an address of operator, which returns the memory address of a variable
for Loop Output
- The output of the code
for (; i < 5; i++) { printf("%d ", i); }
is0 1 2 3 4
Function Definition in C
- The correct way to define a function in C that returns an integer and takes two parameters
a
andb
isint functionName(int a, int b) { }
strcmp() Function
- The
strcmp()
function compares two strings, returning a negative value if the first string is less than the second, zero if they are equal, and a positive value if the first string is greater than the second.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge of C programming with this quiz! Identify valid variable names, predict the output of code snippets, determine the correct way to declare constants, and understand the purpose of the sizeof() operator.