C Programming Quiz

Questions: 16 · 10 minutes
1. What is the value of sizeof(s) in this declaration? char s[] = ""cat"";
3, because only the visible letters count
4, because the array also contains the terminating null character
5, because the declaration adds a length byte
The size of a char pointer
2. What happens when this condition is evaluated with x equal to 0? if (x != 0 && 10 / x > 2)
Both operands are evaluated, causing division by zero
The condition is true because the second operand is ignored
The condition is false, and 10 / x is not evaluated
The code fails to compile because && cannot contain arithmetic
3. What does a directive such as #define MAX 100 primarily do in C?
It creates a variable named MAX at runtime
It instructs the linker to find a symbol named MAX
It defines a macro handled during preprocessing
It creates a type-checked constant object in memory
4. What is the usual purpose of a break statement inside a switch case?
To restart the switch using the next expression value
To skip directly to the default label
To exit the switch and prevent fall-through into later cases
To end the entire program immediately
5. What does malloc return when an allocation succeeds?
A fully initialized object of the requested type
A pointer to a dynamically allocated block of the requested size
A character array that is always filled with zeros
The number of bytes reserved on the stack
6. Which standard header declares the printf function?
<stdio.h>
<stdlib.h>
<string.h>
<math.h>
7. What does this code print? int next(void) { static int n = 0; n++; return n; } int first = next(); int second = next(); printf(""%d %d"", first, second);
1 2
1 1
0 1
2 2
8. Given int a[10]; in the same scope where the array is declared, which expression evaluates to the number of elements in a?
sizeof(a[0])
sizeof(a)
sizeof(a) / sizeof(a[0])
sizeof(&a) / sizeof(int)
9. If p is a pointer to a structure, which operator accesses one of that structure's members through p?
The dot operator: p.member
The scope operator: p::member
The address operator: p&member
The arrow operator: p->member
10. What value does this code print? int sum = 0; for (int i = 1; i <= 5; i++) { if (i % 2 == 0) continue; sum += i; } printf(""%d"", sum);
6
15
10
9
11. What does this code print? int x = 5; int *p = &x; *p = 8; printf(""%d"", x);
5
An indeterminate value
The address of x
8
12. What is printed by this code? int a[3] = {10, 20, 30}; int *p = a; printf(""%d"", p[2]);
10
30
20
The memory address of the third element
13. What character marks the end of a C string?
The null character '\0'
A newline character '\n'
A space character ' '
The end-of-file marker EOF
14. What does this program print? void set_to_zero(int n) { n = 0; } int main(void) { int x = 7; set_to_zero(x); printf(""%d"", x); }
7, because the function receives a copy of x
An indeterminate value, because the function changes n
0, because n refers directly to x
Nothing, because an int cannot be passed to a void function
15. Which mode opens a text file so new output is written at its end rather than replacing its current contents?
""w""
""a""
""rb""
""r+""
16. What value is printed by this loop? int sum = 0; for (int i = 1; i <= 4; i++) { sum += i; } printf(""%d"", sum);
6
9
15
10
Popular tests
Narcissistic Personality Inventory (NPI)
This self-report measure is used to assess narcissism as a personality trai…
Start Test
Yale-Brown Obsessive Compulsive Scale (Y-BOCS)
This measure is used to rapidly quantify the current severity of obsessive…
Start Test
CRAFFT Screening Test (CRAFFT 2.1)
This brief screening measure is designed to identify potential alcohol and…
Start Test
Patient Health Questionnaire-9 (PHQ-9)
This measure is commonly used to quickly screen for the presence and severi…
Start Test
Maslach Burnout Inventory (MBI)
This self-report measure is used to assess occupational burnout symptoms in…
Start Test
Adolescent Anxiety Questionnaire
This measure is designed to support a brief appraisal of anxiety symptoms a…
Start Test
Emotional Creativity Inventory (ECI)
This self-report measure assesses individual differences in the originality…
Start Test
Horne–Ostberg Morningness–Eveningness Questionnaire (MEQ)
Circadian preferences influence typical patterns of alertness and sleep tim…
Start Test
Ambivalent Sexism Inventory (ASI)
This measure is designed to assess attitudes toward women, including both o…
Start Test
Internalized Misogyny Scale (IMS)
This measure is designed to assess internalized negative beliefs and stereo…
Start Test
Perceived Stress Scale (PSS-10)
This self-report measure assesses the degree to which individuals appraise…
Start Test
Impulsive Behavior Scale (SUPPS-P)
Impulsivity is a multidimensional construct that is often assessed with bri…
Start Test
Clinical Institute Withdrawal Assessment for Alcohol, Revised (CIWA-Ar)
This rating scale is used to rapidly assess the severity of alcohol withdra…
Start Test
Positive and Negative Affect Schedule (PANAS)
This measure provides a brief self-report assessment of current or typical…
Start Test
Light Triad Scale (LTS)
This self-report measure assesses prosocial personality tendencies and orie…
Start Test
Suicidal Ideation Scale
In clinical settings, the Suicidal Ideation Scale is used to structure an i…
Start Test
Body Dysmorphic Disorder Scale (BDD-D)
This brief self-report measure is designed to screen for and quantify distr…
Start Test
Beck Anxiety Inventory (BAI)
This measure is a brief self-report inventory used to screen for anxiety sy…
Start Test
Differential Test of Perfectionism
This instrument is used to screen for perfectionism-related attitudes and t…
Start Test
Locus of Control Scale
This measure assesses generalized expectancies regarding the degree to whic…
Start Test
New Apathy Scale
This brief self-report measure is used to screen for apathy-related symptom…
Start Test
Perth Alexithymia Questionnaire (PAQ)
This measure assesses individual differences in alexithymia, including diff…
Start Test
Social Intelligence Scale
This brief self-report measure is designed to support rapid screening of in…
Start Test
Fear Test
This measure is designed to evaluate individual differences in fear-related…
Start Test
Neuroticism Level Scale
The measure is intended for brief screening of an individual’s propensity t…
Start Test
Aggressiveness Indicators Screening Questionnaire
This screening tool is designed to quickly identify behavioral indicators a…
Start Test