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;
}
- 3.5 1
- 3 0
- 4 1
- 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;
}
- 30 20
- 20 11
- 30 21
- 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;
}
- EMENT C
- MENT C
- MENT E
- 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
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
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
- Pseudo-code: Trace loops, recursion and bitwise logic.
- Java: OOP, strings, collections and exceptions.
- Python: Data types, comprehensions and mutability.
- Data Structures: Arrays, stacks, queues, trees, graphs and hashing.
- Algorithms: Complexity, sorting, searching, recursion and DP.
- Object-Oriented Programming: Encapsulation, inheritance, polymorphism, abstraction.
- DBMS: Keys, normalisation, transactions and indexing.
- SQL: Joins, grouping, subqueries and query output.
- Operating Systems: Processes, scheduling, memory and deadlocks.
- Computer Networks: OSI/TCP-IP, protocols, addressing and ports.
- Software Engineering: SDLC, testing, agile and version control.
- Cloud & DevOps: Service models, containers, CI/CD and Linux.
- GenAI Basics: LLMs, tokens, prompting, embeddings and RAG.
Other subjects
- Quantitative Aptitude: Arithmetic, percentages, time and work, speed, probability and data interpretation: the numerical section of every fresher test.
- Logical Reasoning: Series, coding-decoding, arrangements, syllogisms and puzzles: the section that separates prepared candidates from the rest.
- Verbal Ability: Vocabulary, grammar, reading comprehension and sentence order: tested in nearly every IT services hiring exam.
- Python: Python quizzes by topic, from types and strings to classes and generators: output prediction and interview concepts.
- SQL: SQL quizzes by topic, from SELECT and joins to window functions: query output and concepts for analyst and developer roles.
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