This repository contains my learning journey in C, covering basics, control structures, functions, arrays, pointers, file handling, and data structures. Ideal for beginners and students. Explore, run, and modify programs to enhance understanding. Stay tuned for updates! π
Hello World is a simple program that is often used to introduce a new programming language to beginners.
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
Output
Hello, World!
#include <stdio.h>
int main() {
int age = 25;
printf("C Programming");
return 0;
}
Output
C Programming
#include <stdio.h>
int main() {
int age = 25;
printf("%d", age);
return 0;
}
Output
25
#include <stdio.h>
int main() {
int age = 25;
printf("Age: %d", age);
return 0;
}
Output
Age: 25
#include <stdio.h>
int main() {
int age = 25;
printf("Age: %d ", age);
age = 31;
printf("New age: %d", age);
return 0;
}
Output
Age: 25 New age: 31
#include <stdio.h>
int main() {
int age = 25;
printf("Age: %d", age);
age = 31;
printf("\nNew age value: %d", age);
return 0;
}
Output
Age: 25
New age value: 31
#include <stdio.h>
int main() {
int firstNumber = 33;
printf("first Number = %d ", firstNumber);
int secondNumber = firstNumber;
printf("\nsecond Number = %d", secondNumber);
return 0;
}
Output
first Number = 33
second Number = 33
#include <stdio.h>
int main() {
int variable1, variable2;
return 0;
}
#include <stdio.h>
int main() {
int variable1, variable2 = 25;
return 0;
}
Q. Can you guess the output of this program?
#include <stdio.h>
int main() {
int number1 = 33;
printf("%d ", number1);
printf("%d", number2);
return 0;
}
Options a. 33 b. 3333 c. 33 33 d. '33.0'
Correct Answer: c
#include <stdio.h>
int main() {
int age = 10;
printf("%d", age);
return 0;
}
Output
10
#include <stdio.h>
int main() {
int age = 10;
printf("Age = %d", number);
return 0;
}
Output
Age = 10
#include <stdio.h>
int main() {
double number = 12.45;
printf("%lf", number);
return 0;
}
Output
12.450000
#include <stdio.h>
int main() {
double number = 12.45;
printf("%.2lf", number);
return 0;
}
Output
12.45
#include <stdio.h>
int main() {
double number = 12.45;
float number1 = 10.9f;
printf("%.2lf", number);
printf("\n%f", number1);
return 0;
}
Output
12.45
10.900000
#include <stdio.h>
int main() {
double number = 12.45;
float number1 = 10.9f;
printf("%.2lf", number);
printf("\n%.1f", number1);
return 0;
}
Output
12.45
10.9
#include <stdio.h>
int main() {
double number = 5.5e6;
printf("%lf", number);
return 0;
}
Output
5500000.000000
#include <stdio.h>
int main() {
char character = 'z';
printf("%c", character);
return 0;
}
Output
z
#include <stdio.h>
int main() {
char character = 'z';
printf("%c", character);
printf(" %d", character);
return 0;
}
Output
z 122
#include <stdio.h>
int main() {
int age;
double number;
printf("int size = %zu", sizeof (age));
printf("\ndouble size = %zu", sizeof(number));
return 0;
}
Output
int size = 4
double size = 8
Q. What is the output of the following code?
#include <stdio.h>
int main() {
int a = 5;
float a = 9.3;
printf("%d", a);
}
Options
- a. 5
- b. 9.3
- c. 14.3
- d. Error
Answer d
#include <stdio.h>
int main() {
int age;
scanf("%d", &age);
printf("Age = %d", age);
return 0;
}
Output
22
Age = 22
#include <stdio.h>
int main() {
int age;
printf("Enter input value: ");
scanf("%d", &age);
printf("Age = %d", age);
return 0;
}
Output
Enter input value: 22
Age = 22
#include <stdio.h>
int main() {
double number;
char alphabet;
printf("Enter double value: ");
scanf("%lf", &number);
printf("Enter character value: ");
scanf("\n%c", &alphabet);
printf("Number: %lf", number);
printf("\nCharacter: %c", alphabet);
return 0;
}
Output
Enter double value: 22.1
Enter character value: z
Number: 22.100000
Character: z
#include <stdio.h>
int main() {
double number;
char alphabet;
printf("Enter input values: ");
scanf("%lf %c", &number, &alphabet);
printf("Number: %lf", number);
printf("\nCharacter: %c", alphabet);
return 0;
}
Output
Enter input values: 30.6
c
Number: 30.600000
Character: c
Q. What is the correct way to take double input?
Options
- scanf("%d", &input);
- scanf("%f", &input);
- scanf("%lf", &input);
- scanf("%c", &input);
Answer: 3
#include <stdio.h>
int main() {
// create a variable
int data = 34;
// print the value of data variable
printf("Data = %d", data);
return 0;
}
Output
Data = 34
#include <stdio.h>
int main() {
int data = 34; // create a variable
printf("Data = %d", data); // print the variable
return 0;
}
Output
Data = 34
#include <stdio.h>
int main() {
int age;
double height;
printf("Enter the age: ");
scanf("%d", &age);
printf("Enter the height: ");
scanf("%lf", &height);
printf("Age = %d", age);
printf("\nHeight = %.1lf", height);
return 0;
}
Suppose, height input is not required so we will comment it out
#include <stdio.h>
int main() {
int age;
// double height;
printf("Enter the age: ");
scanf("%d", &age);
// printf("Enter the height: ");
// scanf("%lf", &height);
printf("Age = %d", age);
// printf("\nHeight = %.1lf", height);
return 0;
}
Output
Enter the age: 29
Age = 29
This program takes age input from the user
It stores it in the age variable
And, print the value using printf()
#include <stdio.h>
int main() {
int age;
printf("Enter the age: ");
scanf("%d", &age);
printf("Age = %d", age);
return 0;
}
Multiline commenting above program
/* This program takes age input from the user
It stores it in the age variable
And, print the value using printf() */
#include <stdio.h>
int main() {
int age;
printf("Enter the age: ");
scanf("%d", &age);
printf("Age = %d", age);
return 0;
}
Output
Enter the age: 29
Age = 29
/* This program takes age input from the user
It stores it in the age variable
And, print the value using printf() */
#include <stdio.h>
int main() {
int age;
printf("Enter the age: ");
scanf("%d", &age);
printf("Age = %d", age);
return 0;
}
// This program takes age input from the user
// It stores it in the age variable
// And, print the value using printf()
#include <stdio.h>
int main() {
int age;
printf("Enter the age: ");
scanf("%d", &age);
printf("Age = %d", age);
return 0;
}
Q. What is the correct way to comment in C programming?
Options
- //
- #
- <!--->
- All of the above
Answer: 1