1.Comments: Comments are used to add notes or explanations to your code. They start with /* and end with */ for multiline comments, or with // for single-line comments.
2.Data types: C supports several data types, including int for integers, float for floating-point numbers, double for double-precision floating-point numbers, char for characters, and void for empty value.
3.Variables: Variables are used to store values of a particular data type. They must be declared before they can be used, using the syntax datatype variable_name;. For example, int num; declares an integer variable named num.
4.Operators: C supports various operators, including arithmetic operators (+, -, *, /, %), comparison operators (<, >, <=, >=, ==, !=), and logical operators (&&, ||, !).
5.Control structures: Control structures allow you to control the flow of your program. C supports conditional statements, such as if-else and switch, as well as looping structures, such as for, while, and do-while.
6.Functions: Functions are used to group together a block of code that performs a specific task.
They are declared using the syntax :
return_type function_name(parameters)
{
// function body
}
For example, int add(int a, int b) { return b; } declares a function named add that takes two integer parameters and returns their sum.
Here’s an example program that demonstrates some of the basic syntax in C:
#include
int main() {
int num1, num2, sum;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
sum = num1 + num2;
printf("The sum of %d and %d is %d", num1, num2, sum);
return 0;
}
This program prompts the user to enter two numbers, calculates their sum, and displays the result on the screen using the printf function. The program uses variables (num1, num2, and sum), operators (+), control structures (printf, scanf, and return), and functions (main and printf).
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.