There are some steps to write the First Program in C Language
1. Install a C Compiler
Before you start writing C programs, you need to install a C compiler. If you did not install then please check my last article for How to install C Compiler on your machine.
2. Create Your First Program
Once you have the compiler installed, you can create your first program. Let’s write a basic “Hello, techfliez.com!” program.
Example:
#include <stdio.h> // Preprocessor directive to include standard input/output header file
int main() {
printf("Hello, techfliez.com!"); // Prints "Hello, techfliez.com!" to the console
return 0; // Exit the program successfully
}
Explanation of the Code:
#include<stdio.h>: This tells the compiler to include the standard input/output library that allows us to use functions like printf.
int main(): This is the entry point of every C program. The program starts executing here.
printf(“Hello, techfliez.com!”);: This line prints the message Hello, techfliez.com! to the screen.
return 0;: This indicates that the program has successfully completed and returns control to the operating system.
3. Save and Compile the Program
1. Save the program in a file with the .c extension, for example, hello.c.
2. Now, open a terminal/command prompt and navigate to the directory where your program is saved.
3. To compile the program, use the following command (assuming you’re using GCC).
gcc hello.c -o hello
This will create an executable file called hello (or hello.exe on Windows).
4. Run the Program
After compilation, you can run your program:
On Linux/macOS:
./hello
On Windows:
hello
Output:
Writing your First C Program – Interview Questions
Q 1: What is the basic structure of a C program?
Q 2: Why is main() function important?
Q 3: What does #include do?
Q 4: What is printf() used for?
Q 5: What does return 0; indicate in a C program?
Writing your First C Program – Objective Questions (MCQs)
Q1. Which function is the entry point of a C program?
Q2. Which header file is required for printf()?
Q3. Which symbol is used to end a statement in C?
Q4. What does printf() do?
Q5. Which function is used to take input from user?