C language interview questions cover program structure, classic algorithms like Armstrong numbers and Fibonacci series, pointer concepts and compilation errors. In Indian campus placements at TCS, Infosys and Wipro, these questions appear in nearly every first technical round. Mastering them gives freshers and career switchers a reliable edge in written tests and face-to-face interviews.
- Key Takeaway 1: Every valid C program follows a predictable six-section structure, from the documentation section at the top to the main function at the bottom.
- Key Takeaway 2: Classic programs like Armstrong numbers, leap year checks, even-odd logic and Fibonacci series are asked repeatedly in TCS, Infosys, Wipro and HCL campus drives.
- Key Takeaway 3: You compile and run C programs using gcc from the terminal; errors like error ld returned 1 exit status and createprocess error 2 have specific, fixable causes.
- Key Takeaway 4: Knowing how to swap two numbers both with and without a temporary variable is a staple question in every beginner-level technical round.
- Key Takeaway 5: Practising these programs alongside structured courses is the fastest path to interview readiness, especially if you are a fresh graduate or career switcher.
The Basic Structure of a C Program, Section by Section
The structure of a C program is not optional or stylistic. It is a defined layout that the compiler expects, and understanding each section helps you write code that is readable, maintainable and error-free from day one.
A standard C program has six sections in this order: documentation, preprocessor directives, global declarations, the main() function, user-defined functions and, optionally, a link section. Most beginners skip straight to main(), which works for tiny scripts but causes confusion the moment code grows.
The Documentation Section
The documentation section sits at the very top of your file. It is a block of comments that describes what the program does, who wrote it, when it was written and any version notes. In C, you write multi-line comments inside /* */ and single-line comments with //.
This section is ignored by the compiler entirely. But during code reviews, internships and team projects, clear documentation separates professional code from student-level submissions. Indian placement officers at companies like Cognizant and Accenture specifically look for this habit.
Preprocessor Directives and Global Declarations
Lines starting with # are preprocessor directives. The most common is #include <stdio.h>, which tells the compiler to include the standard input-output header before compilation begins. You will also see #define used to create constants.
Global declarations come next. Variables declared here are accessible across all functions in the file, unlike local variables which live only inside the function where they are defined. Use globals sparingly; overusing them makes programs harder to debug.
The main() Function and User-Defined Functions
Every C program must have exactly one main() function. Execution always starts here. The return type is int, and returning 0 signals successful execution to the operating system.
User-defined functions are declared either before main() or after it with a forward declaration (prototype) at the top. A function in C programming example looks like this: int square(int n) { return n * n; }. Splitting logic into functions makes your code modular, testable and far easier to explain in interviews.
Classic C Programs Asked in Campus Placement Interviews
Interviewers use these programs to test whether you understand loops, conditionals and mathematical logic, not just syntax. According to Unstop’s 2023 Campus Placement Report, over 68% of engineering campus placement technical rounds in India include at least one basic programming question in C or C++. A separate analysis by Naukri.com published in their 2024 Hiring Trends Report found that C language proficiency is listed as a required or preferred skill in over 42% of entry-level software and embedded engineering job postings in India.
Armstrong Number Program in C
An Armstrong number is a number equal to the sum of its own digits each raised to the power of the number of digits. For example, 153 is an Armstrong number because 1 cubed plus 5 cubed plus 3 cubed equals 153. The armstrong number program in c uses a while loop to extract each digit, raises it to the appropriate power and accumulates the sum.
The logic for an armstrong number in c: store the original number, count its digits, then loop through each digit using modulo and division. Compare the final sum to the original. If they match, it is an Armstrong number. This exact question appeared in the TCS NQT 2023 and 2024 coding sections.
Fibonacci Series in C
The fibonacci series in c starts with 0 and 1, and every subsequent term is the sum of the two before it: 0, 1, 1, 2, 3, 5, 8, 13. You can write this iteratively using a for loop (preferred in interviews for clarity) or recursively (preferred when demonstrating function concepts).
The iterative version uses three variables: two to hold the last two values and one as a temporary swap holder. Interviewers often ask you to print the first N terms, find the Nth term or check if a given number belongs to the series. Know all three variants.
Swapping Two Numbers in C
Swapping two numbers in C is asked in almost every first-round technical interview. There are two standard approaches. The first uses a temporary variable: store a in temp, assign b to a, then assign temp to b. Clean, readable and always correct.
The second approach swaps without a third variable using arithmetic: a = a + b; b = a - b; a = a - b;. Some interviewers also ask for the XOR bitwise method. Know when each approach can fail. The arithmetic method overflows with very large integers, which is worth mentioning to show depth.
Leap Year and Even-Odd Programs
A leap year program in C uses a nested if-else condition: a year is a leap year if it is divisible by 4, but century years (divisible by 100) must also be divisible by 400. The even odd program in C is simpler: use the modulo operator (% 2 == 0 means even). Both are warm-up questions that test whether you can translate a rule into code quickly.
| Program | Core Concept Tested | Common Interview Context | Difficulty |
|---|---|---|---|
| Armstrong Number | Loops, modulo, power function | TCS NQT, Infosys Instep | Beginner |
| Fibonacci Series | Iteration, recursion | Wipro NLTH, HCL TechBee | Beginner |
| Swap Two Numbers | Variables, arithmetic, XOR | All campus drives, first rounds | Beginner |
| Leap Year Check | Nested conditionals, divisibility | Cognizant GenC, Capgemini | Beginner |
| Even-Odd Check | Modulo operator | Screening rounds, hackathons | Beginner |
If you want to build these skills alongside other high-demand technical abilities, check out this guide to top skills every college student must learn before graduation. C programming consistently ranks near the top of that list for engineering and IT students across India.
How to Compile and Run a C Program from the Terminal
Knowing how to run a C program in the command prompt is a practical skill that separates people who only write code in an IDE from those who understand what is actually happening under the hood. Recruiters notice the difference.
Step-by-Step: Compiling with GCC
- Install GCC. On Windows, use MinGW or WSL. On Ubuntu or any Linux distro, run
sudo apt install gcc. On macOS, install Xcode Command Line Tools. - Write your program and save it as
hello.c. - Open your terminal or command prompt and navigate to the folder containing the file.
- Run:
gcc hello.c -o hello - Execute the output:
./helloon Linux/macOS orhello.exeon Windows.
Fixing Common Compilation Errors
The error gcc failed with exit status 1 means your code has a syntax or logical error. Read the line number in the error message and fix that specific issue first before re-running. Do not try to fix multiple errors simultaneously when you are starting out.
createprocess error 2, the system cannot find the file specified appears on Windows when GCC is not added to your system PATH. This is one of the most common setup problems reported by students using Windows laptops in Indian college computer labs. Fix it by going to System Properties, editing the Path environment variable and adding the MinGW bin folder. Restart the terminal after.
Error ld returned 1 exit status is a linker error, not a compiler error. It usually means you have called a function that does not exist or a library is not linked. Check your function names for typos and make sure you have included the right headers.
If you are learning programming as part of a broader career plan, our list of top online courses for high-salary jobs includes several structured paths that cover C, Python and systems programming together. That combination is particularly valued in embedded systems and cybersecurity roles.
C Language Interview Questions: What Actually Gets Asked
Most c language interview questions in Indian campus placements fall into four buckets: program output prediction, write-a-program tasks, concept explanation and error debugging. Knowing which bucket a question belongs to helps you structure your answer faster. According to GeeksforGeeks’ 2024 Interview Preparation Guide, pointer-related questions and string manipulation programs are the two most frequently asked C topics in product-based company interviews, making them the highest-priority areas for any fresher preparing for technical rounds.
Concept Questions You Will Definitely Face
- What is the difference between
printfandscanf? - What is a pointer and how does it differ from a regular variable?
- Explain the difference between
call by valueandcall by reference. - What is the use of the
statickeyword in C? - What is the difference between
structandunion? - How does memory allocation work with
mallocandfree? - What is the
c max functionand how do you find the maximum of two numbers without using it? - What are the basic data types in C and what is the size of each?
- What is the difference between C and C++ for interview purposes?
Program-Writing Questions You Must Practise
- Write a C program to check if a number is prime.
- Write a C program to reverse a string without using
strrev. - Convert a number to string in C (the
num to string cquestion, typically solved withsprintforitoa). - Print the Fibonacci series up to N terms.
- Check if a given number is an Armstrong number.
- Swap two numbers without a third variable.
Spending at least 30% of your prep time on pointers alone is worth it. Pair pointer practice with string manipulation programs and you will cover the two highest-frequency categories in a single focused study block.
If you are actively planning your career around programming skills, the 3.0 University guide on how to choose the right career path after graduation breaks down which technical specialisations are growing fastest and which C-adjacent skills (like embedded C and systems programming) employers are actively hiring for.
You might also want to explore best career options in 2026 for students and professionals to see where C programming fits into larger technology career tracks, especially in cybersecurity, IoT and defence tech sectors where C is still the dominant language.
For fresh graduates trying to land their first role, the entry-level jobs guide for teens and graduates covers which companies hire C programmers at the fresher level and what their technical screening process looks like. Pair that with practice on the programs listed above and you will walk into interviews with real confidence.
Free resources can get you started, but structured learning accelerates the process. The best free online learning platforms for students article lists platforms where you can practise C problems with instant feedback, which is far more effective than just reading theory.
Once you are solid on C, the natural next step is pairing it with a certification that employers recognise. The 3.0 University course catalogue covers Cybersecurity, Ethical Hacking, AI and Blockchain, all of which build directly on systems-level programming knowledge.
Frequently Asked Questions
What is the basic structure of a C program?
A standard C program has six sections: the documentation section (comments describing the program), preprocessor directives like #include, global declarations, the main() function, user-defined functions and an optional link section. Execution always begins at main(), and the program returns 0 to the OS on successful completion.
How do you write an Armstrong number program in C?
Store the original number, count its digits, then use a while loop to extract each digit using modulo (% 10) and divide by 10 each iteration. Raise each digit to the power of the digit count using a loop or pow(), accumulate the sum and compare it to the original. If they are equal, it is an Armstrong number.
How do you swap two numbers in C?
The standard method uses a temporary variable: temp = a; a = b; b = temp;. Without a third variable, use arithmetic: a = a + b; b = a - b; a = a - b;. Note that the arithmetic method can overflow with very large integers. A bitwise XOR swap also works and is sometimes asked in advanced rounds.
How do you run a C program in the command prompt?
Install GCC, write your program and save it as filename.c. Open the terminal, navigate to the file directory and run gcc filename.c -o output. Then execute it with ./output on Linux/macOS or output.exe on Windows. If you see createprocess error 2, GCC is not in your system PATH.
Which C programs are commonly asked in TCS NQT?
TCS NQT regularly includes Armstrong number programs, Fibonacci series (both iterative and recursive), prime number checks, string reversal and swap-without-third-variable questions. The 2023 and 2024 TCS NQT coding sections specifically featured Armstrong number and Fibonacci logic as standalone tasks in the beginner coding slot.
What is the difference between C and C++ for interview purposes?
C is a procedural language with no built-in support for classes or objects. C++ extends C with object-oriented programming features like classes, inheritance and polymorphism. For campus placement c language interview questions, you are expected to know C syntax, pointers and memory management. C++ questions additionally cover OOP concepts, STL and constructors.
What are the most common c language interview questions for freshers?
The most common c language interview questions for freshers include: explain pointers and memory allocation, write an Armstrong or Fibonacci program, swap two numbers without a third variable, difference between struct and union, call by value vs call by reference, and basic C syntax rules around data types and variables. Companies like TCS, Infosys and Wipro use these in both written tests and face-to-face technical rounds.
The programs and concepts covered here are your practical foundation. Write every one of them from scratch, test them in the terminal and understand each error message you see. That hands-on habit is what separates candidates who pass technical rounds from those who do not.
If you are ready to go beyond C and build skills that open doors in high-growth tech fields, explore 3.0 University’s certification programmes in Cybersecurity, Ethical Hacking, Artificial Intelligence, Blockchain and Web3. These courses are designed for students, working professionals and career switchers who want practical, industry-ready skills without spending years in a classroom.
Last updated: September 2026. Reviewed by the 3University editorial team.