Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT SWIFT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

C Tutorial

C HOME C Intro C Get Started C Syntax C Output C Comments C Variables C Data Types C Type Conversion C Constants C Operators C Booleans C If...Else C Switch C While Loop C For Loop C Break/Continue C Arrays C Strings C User Input C Memory Address C Pointers

C Functions

C Functions C Function Parameters C Scope C Function Declaration C Math Functions C Inline Functions C Recursion C Function Pointers

C Files

C Create Files C Write To Files C Read Files

C Structures

C Structures C Nested Structures C Structs & Pointers C Unions C typedef C Struct Padding

C Enums

C Enums

C Memory

C Memory Management

C Errors

C Errors C Debugging C NULL C Error Handling C Input Validation

C More

C Date C Random Numbers C Macros C Organize Code C Storage Classes C Bitwise Operators C Fixed-width Integers

C Projects

C Projects

C Reference

C Reference C Keywords C <stdio.h> C <stdlib.h> C <string.h> C <math.h> C <ctype.h> C <time.h>

C Examples

C Examples C Real-Life Examples C Exercises C Quiz C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate

C Interview Questions


C Interview Questions with Answers

This page gives simple C interview questions with short answers. The questions are made for beginners, so you can use them to study for tests and job interviews.

  • Core C basics and program structure
  • Variables and data types
  • Conditions and loops
  • Arrays and strings
  • Pointers and memory
  • Functions, scope, and structures

Core C Basics

1. What is C used for?

Answer:

  • C is a programming language used to write fast and efficient programs.
  • It is often used for system software, embedded systems, and performance-critical applications.

2. What is the basic structure of a C program?

Answer:

  • A typical C program has #include lines, a main() function, and C statements inside { }.
#include <stdio.h>

int main() {
  printf("Hello World!");
  return 0;
}

3. What does the main() function do in C?

Answer:

  • main() is the starting point of every C program.
  • The code inside main() runs first when the program starts.
  • The return 0; line usually means "the program ended successfully".

4. What is the purpose of #include <stdio.h>?

Answer:

  • #include <stdio.h> tells the compiler to include the standard input/output library.
  • It lets you use functions like printf() and scanf().

5. What does printf() do?

Answer:

  • printf() prints text and values to the screen.
  • You can use format specifiers like %d for integers and %f for floating-point numbers.
#include <stdio.h>

int main() {
  int age = 30;
  printf("Age: %d\n", age);
  return 0;
}

Variables and Data Types

6. What is a variable in C?

Answer:

  • A variable is a named place in memory where a value is stored.
  • In C, you must declare the type before the variable name.
int count = 10;
float price = 19.95;
char grade = 'A';

7. What is the difference between int, float, and char?

Answer:

  • int stores whole numbers (e.g. 3, -10, 200).
  • float stores numbers with decimals (e.g. 3.14, -0.5).
  • char stores a single character (e.g. 'A', 'B').

8. What is a constant and why would you use one?

Answer:

  • A constant is a value that cannot be changed once it is set.
  • Using const makes your intent clear and protects the value from being changed by mistake.
const int DAYS_IN_WEEK = 7;
// DAYS_IN_WEEK = 8; // not allowed

9. How do you read user input in C?

Answer:

  • You can use scanf() to read values from the keyboard.
  • You must pass the address of the variable using &.
int number;
scanf("%d", &number);

Conditions and Loops

10. What is an if statement used for?

Answer:

  • An if statement lets the program make a decision.
  • Code inside the if block runs only when the condition is true.
int age = 20;

if (age >= 18) {
  printf("Adult\n");
} else {
  printf("Not adult\n");
}

11. What is a loop in C?

Answer:

  • A loop repeats the same block of code multiple times.
  • C has for, while, and do...while loops.
for (int i = 1; i <= 5; i++) {
  printf("%d\n", i);
}

12. What is the difference between while and do...while?

Answer:

  • while checks the condition before running the loop body.
  • do...while runs the loop body once, then checks the condition.
  • This means do...while always runs at least one time.

13. What is a switch statement?

Answer:

  • A switch statement chooses one block of code to run based on the value of an expression.
  • Each option is written as a case, and default handles all other values.
int day = 2;

switch (day) {
  case 1:
    printf("Monday");
    break;
  case 2:
    printf("Tuesday");
    break;
  default:
    printf("Another day");
}

Arrays and Strings

14. What is an array in C?

Answer:

  • An array stores many values of the same type in one variable name.
  • You access each element by its index, starting from 0.
int scores[3] = {10, 20, 30};
printf("%d\n", scores[0]); // first element

15. How are strings represented in C?

Answer:

  • In C, a string is an array of characters.
  • It ends with a special character '\0' (the null terminator).
char greeting[] = "Hello";
printf("%s\n", greeting);

Pointers and Memory

16. What is a pointer in C?

Answer:

  • A pointer is a variable that stores the memory address of another variable.
  • Pointers are used to work directly with memory and to share data with functions.
int value = 10;
int *ptr = &value;  // ptr holds the address of value

17. What do the & and * operators mean with pointers?

Answer:

  • & gives the address of a variable (the "address of" operator).
  • * gives the value at an address (the "dereference" operator).
int x = 5;
int *p = &x;    // &x is the address of x
printf("%d\n", *p); // *p is the value at that address (5)

18. What is a NULL pointer?

Answer:

  • A NULL pointer is a pointer that does not point to any valid memory location.
  • It is often used to show that the pointer is "empty" or not yet set.
int *ptr = NULL;  // pointer not pointing anywhere yet

Functions, Scope, and Structures

19. What is a function in C and why use it?

Answer:

  • A function is a block of code that performs a specific task.
  • Functions help you split a large program into smaller, reusable pieces.
int add(int a, int b) {
  return a + b;
}

20. What is the difference between local and global variables?

Answer:

  • A local variable is declared inside a function and can be used only there.
  • A global variable is declared outside all functions and can be used in the entire file (after its declaration).

21. What is a struct in C?

Answer:

  • A struct (structure) is a custom type that groups related variables under one name.
  • The grouped variables can have different types.
struct Person {
  char name[50];
  int age;
};

22. Why would you use a struct instead of separate variables?

Answer:

  • A struct keeps related information together, making the code easier to understand.
  • It is useful when you want to treat multiple pieces of data as one unit (for example, a person or a product).


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.