Dayrvia
C

C · Practice questions

Try 16 questions on C, then read the explanations and review the related concepts.

Practice questions

Choose an answer and move to the next question. Grade the last one to see explanations and review links.

16 questions
Q1 What value is stored in n?
int n = 9 / 4;
Q2 Which expression reads the last element?
int a[] = {3, 7, 9};
Q3 What is n after the final line?
int n = 3;
int *p = &n;
*p = 8;
Q4 What is s after the loop?
int s = 0;
for (int i = 1; i < 5; i += 2) s += i;
Q5 What does *(p + 1) read?
int a[] = {5, 8, 13, 21};
int *p = a + 1;
Q6 What is right - left?
int a[6];
int *left = &a[1], *right = &a[5];
Q7 What are a[0] and *p now?
int a[] = {2, 7};
int *p = a;
(*p)++;
Q8 What are old and *p in the next statement?
int a[] = {6, 10};
int *p = a;
int old = *p++;
Q9 At this declaration site, what is sizeof a / sizeof a[0]?
int a[] = {7, 0, 2, 8};
Q10 Why does this function accept n?
int sum(const int values[], size_t n);
Q11 Which statement is allowed?
int a = 1, b = 2;
const int *p = &a;
Q12 Which assignment is allowed?
int x = 5, y = 9;
int *const p = &x;
Q13 What are a and b at the end?
int a = 1, b = 4;
int *p = &a;
int **pp = &p;
*pp = &b;
**pp = 6;
Q14 Which call updates x?
void set(int *p) { *p = 12; }
int x = 3;
Q15 What should be checked before writing through p?
int *p = malloc(sizeof *p);
Q16 Assuming p owned a successful allocation, how should alias be treated?
int *alias = p;
free(p);
p = NULL;
Original practice questions written for Dayrvia.