Video Link: https://youtu.be/L2H2rtCLB-0 Tutorial Link: https://www.programiz.com/c-programming
#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