🎯 Top 70 C Programming Viva Questions with Detailed Answers – Part 1

(Basics, Operators & Decision Making)

📚 Covers: Basics | Data Types | Input/Output | Operators | Decision Making
🎯 Perfect for C Programming Viva Questions for Beginners & Interviews
✍️ Learning Growth Hub


🚀 Introduction

If you are preparing for:

  • C programming viva questions for beginners

  • Practical lab exams

  • Internal assessments

  • C programming interview questions

Then understanding concepts clearly is more important than memorizing short definitions.

This guide explains each question with logic, examples, and simple explanations so you can confidently answer in viva or interviews.

This is Part 1 of the complete 70-question series.


📌 Table of Contents

  1. Basics of C Programming

  2. Input and Output in C

  3. Operators in C

  4. Decision Making in C


🟢 SECTION 1: Basics of C Programming


1️⃣ What is C language?

C is a general-purpose procedural programming language developed by Dennis Ritchie in 1972 at Bell Labs.

It was mainly created for system programming and operating systems.

Why C is important:

  • It is the foundation of modern languages like C++ and Java

  • It provides low-level memory access using pointers

  • It is fast and efficient

  • It is widely used in embedded systems

In simple words, C helps you understand how computers work internally with memory and data.


2️⃣ Why is C called a middle-level language?

C is called a middle-level language because it combines:

✔ High-level features (loops, functions, conditions)
✔ Low-level features (memory access, pointers)

High-level languages hide hardware details.
Low-level languages interact directly with hardware.

C provides both power and control.


3️⃣ What is a variable?

A variable is a named memory location used to store data.

Example:

int age = 20; // Declare an integer variable named age and assign value 20

When this runs:

  • Memory is reserved in RAM

  • The name age is assigned

  • Value 20 is stored

Variables allow programs to store and manipulate values dynamically.


4️⃣ What are data types in C?

Data types define the type of value a variable can store and how much memory it requires.

Common data types:

  • int → Whole numbers (4 bytes)

  • float → Decimal numbers (4 bytes)

  • char → Single character (1 byte)

  • double → Large decimal numbers (8 bytes)

Data types are important because memory allocation depends on them.


5️⃣ What is the difference between int and float?

int float
Stores whole numbers Stores decimal numbers
Example: 10 Example: 10.5
Cannot store fractions Can store fractions

If you store 10.5 in an int, the decimal part is lost.

6️⃣ What is a constant?

A constant is a fixed value that cannot be changed during program execution.

Example:

const int x = 10; // Declare a constant integer x with value 10 (cannot be changed)

If you try to change x later, the compiler gives an error.

Constants improve code safety and readability.


7️⃣ What is main() function?

main() is the entry point of every C program.

Execution steps:

  1. Program starts from main()

  2. Statements execute sequentially

  3. Program ends when main() finishes

Without main(), the program cannot run.


8️⃣ What is a header file?

A header file contains function declarations and macros.

Example:

#include <stdio.h> // Includes standard input-output library for printf() and scanf()

stdio.h contains declarations for:

  • printf()

  • scanf()

Header files allow us to use built-in library functions.


9️⃣ What is return 0 in C?

return 0; // Ends the program and returns success status to the operating system

It indicates successful execution of the program.

  • 0 → Success

  • Non-zero → Error

It sends status back to the operating system.


🔟 What is a keyword in C?

Keywords are reserved words with predefined meaning.

Examples:

  • int

  • return

  • if

  • while

  • for

Keywords cannot be used as variable names.


🟢 SECTION 2: Input and Output in C


1️⃣1️⃣ What is printf()?

printf() is a library function used to display output on screen.

It is defined in stdio.h.

Example:

printf("Hello World"); // Prints "Hello World" on the screen

It supports formatted output, meaning you can print variables along with text.


1️⃣2️⃣ What is scanf()?

scanf() is used to take input from the user.

Example:

int num; // Declare an integer variable scanf("%d", &num); // Take integer input from user and store it in num

It reads data from keyboard and stores it in a variable.


1️⃣3️⃣ Why do we use & in scanf()?

& is the address-of operator.

scanf() needs the memory address where the value should be stored.

Example:

scanf("%d", &num); // &num gives the memory address where input value will be stored

&num gives the memory address of num.

Without &, scanf() cannot store input properly.


1️⃣4️⃣ What is a format specifier?

Format specifiers tell printf() and scanf() the type of data.

Examples:

  • %d → integer

  • %f → float

  • %c → character

  • %s → string

Using incorrect format specifier may cause unexpected output.


1️⃣5️⃣ What is %d used for?

%d is used to print or read integer values.

Example:

int x = 5; // Declare integer variable x and assign value 5 printf("%d", x); // Print value of x using integer format specifier

🟢 SECTION 3: Operators in C


1️⃣6️⃣ What are operators?

Operators are symbols that perform operations on variables or values.

Examples:

  • + (Addition)

  • - (Subtraction)

  • * (Multiplication)

  • / (Division)


1️⃣7️⃣ Types of operators in C?

  • Arithmetic operators (+ - * / %)

  • Relational operators (== != > < >= <=)

  • Logical operators (&& || !)

  • Assignment operators (= += -= *=)

  • Increment/Decrement (++ --)


1️⃣8️⃣ What is the difference between = and == ?

= ==
Assignment operator Comparison operator
Assigns value Compares values

Example:
x = 5; // Assign value 5 to variable x x == 5; // Compare whether x is equal to 5 (returns true or false)

1️⃣9️⃣ What is modulus operator?

% returns the remainder of division.

Example:

10 % 3; // Divides 10 by 3 and returns remainder 1

Commonly used to check even or odd numbers.


2️⃣0️⃣ What are logical operators?

Logical operators combine multiple conditions.

  • && → True if both conditions are true

  • || → True if at least one condition is true

  • ! → Reverses condition

Used mainly in decision making.


🟢 SECTION 4: Decision Making in C


2️⃣1️⃣ What is if statement?

The if statement executes a block only when condition is true.

Example:

int x = 5; // Declare integer variable x and assign value 5 if (x > 0) { // Check if x is greater than 0 printf("Positive"); // Print "Positive" if condition is true }

2️⃣2️⃣ What is if-else statement?

if-else provides two possible execution paths.

Example:

int num = 4; // Declare integer variable num and assign value 4 if (num % 2 == 0) // Check if num is divisible by 2 printf("Even"); // Print "Even" if condition is true else printf("Odd"); // Print "Odd" if condition is false

2️⃣3️⃣ What is nested if?

A nested if is an if statement inside another if.

Used when multiple conditions must be checked.


2️⃣4️⃣ What is switch statement?

switch is used when selecting one option from multiple fixed values.

Example:

int day = 1; // Declare integer variable day and assign value 1 switch(day) { // Check value of day case 1: // If day equals 1 printf("Monday"); // Print Monday break; // Exit switch statement default: // If no case matches printf("Invalid"); // Print Invalid }

2️⃣5️⃣ Difference between if and switch?

if switch
Can check ranges Cannot check ranges
Works with complex conditions Works with fixed values
Supports logical operators Does not support logical expressions






📊Here’s a quick visual summary of the basic concepts in C programming.

This cheat sheet covers variables, data types, operators, input/output, decision-making statements, and program flow.

Use this image as a reference while studying the concepts explained in this guide.




Note: This diagram is a handy reference for beginners to quickly recall C programming concepts.

Make sure to practice each concept with small programs to strengthen your understanding and prepare effectively for viva or exams.



🎯 Conclusion

These 25 detailed C programming viva questions cover:

✔ Basics of C
✔ Data Types
✔ Input and Output
✔ Operators
✔ Decision Making

If you understand these clearly, your C fundamentals are strong.

👉 Continue to Part 2 – Loops & Functions
👉 Continue to Part 3 – Pointers & Memory Concepts



📌 Keep Learning. Keep Coding. Keep Growing.

✨ Written by Krishna Popat
🌱 Founder, Learning Growth Hub

Comments

Popular posts from this blog

🌟 The Honest Journey of a Student: Learning, Failing, and Growing

“C Programming for Beginners: Master Variables, Data Types, and Memory (Bits Explained)”