Basic C Programs with Explanations and Output
1. C Hello World Program
Code:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
Explanation:
This program prints 'Hello, World!'. It uses printf() from stdio.h, and main() is the entry point.
Sample Output:
Hello, World!
2. C Program to Print Your Own Name
Code:
#include <stdio.h>
int main() {
printf("My name is Preethi.");
return 0;
Explanation:
Replaces Hello World with your name. You can change the string to print your own name.
Sample Output:
My name is Preethi.
3. C Program to Print an Integer Entered By the User
Code:
#include <stdio.h>
int main() {
int number;
printf("Enter an integer: ");
scanf("%d", &number);
printf("You entered: %d\n", number);
return 0;
Explanation:
Takes an integer input from user using scanf() and prints it back using printf().
Sample Output:
Enter an integer: 5
You entered: 5