C Programming questions and answers

Output prediction, pointers and operators. Practise c programming questions from the technical & programming section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.

Sample c programming questions with worked answers

Question 1

What will be the output of the following C program?

#include <stdio.h>

int main(void) {
    int a = 7, b = 2;
    printf("%d %d", a / b, a % b);
    return 0;
}
  1. 3.5 1
  2. 3 0
  3. 4 1
  4. 3 1

Answer: D. 3 1

Explanation: Both operands are int, so 7 / 2 is integer division giving 3, and 7 % 2 is the remainder 1.

Question 2

What will be the output of the following C program?

#include <stdio.h>

int main(void) {
    int a[] = {10, 20, 30, 40};
    int *p = a;
    p += 2;
    printf("%d %d", *p, *(p - 1) + 1);
    return 0;
}
  1. 30 20
  2. 20 11
  3. 30 21
  4. 12 21

Answer: C. 30 21

Explanation: p starts at a[0]; after p += 2 it points to a[2] = 30. *(p - 1) is a[1] = 20, and adding 1 gives 21.

Question 3

What will be the output of the following C program?

#include <stdio.h>

int main(void) {
    char s[] = "PLACEMENT";
    char *p = s + 3;
    printf("%s %c", p + 2, *(p + 1));
    return 0;
}
  1. EMENT C
  2. MENT C
  3. MENT E
  4. CEMENT E

Answer: C. MENT E

Explanation: In "PLACEMENT", p = s + 3 points to 'C'. p + 2 points to 'M', so %s prints "MENT", and *(p + 1) is 'E'.

All 30 c programming questions with answers

C Programming: common questions

What are c programming questions?

Output prediction, pointers and operators. They appear in the technical & programming section of many placement tests.

Where can I practise c programming questions with answers for free?

Right here on LogicWiz Exams. Every c programming question has a worked explanation after you answer. Practice is free and needs no sign-up.

How should I practise c programming?

Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.

Start practising

On this page you can start a fresh set of c programming questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: Technical & Programming practice.

More technical & programming topics

Other subjects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep