Basic Syntax of C Programming:
Basic Syntax of C Programming |
C language syntax specify rules for sequence of characters to be written in C language. In simple language it states how to form statements in a C language program - How should the line of code start, how it should end, where to use double quotes, where to use curly brackets etc.
The rule specify how the character sequence will be grouped together, to form tokens. A smallest individual unit in C program is known as C Token. Tokens are either keywords, identifiers, constants, variables or any symbol which has some meaning in C language. A C program can also be called as a collection of various tokens.
Statement:
The command given to the computer which causes the computer to carry out some action is called statement. It is of 2 types.
a)Simple Statement:
Statement consists of an expression followed by a semicolon is called simple statement. Eg: a=2;
b) Compound Statement:
A compound statement consists of several individual statements enclosed in a pair of braces { }. It provides capability for embedding statements within other statements.
Example:
{
l=2;
b=3;
area=l*b;
}
Q. Program for Adding two integer number:
#include<stdio.h> //header file included for standard input output
#include<conio.h> //header file included for console input output
void main() // main function
{
int num1=2; // 2 is assigned to integer variable num1
int num2=6; // 6 is assigned to integer variable num2
int sum; // variable declared to store sum
sum = num1 + num2; // num1 & num2 value is added and store to sum
printf("The Sum=%d", sum); //value of sum is displayed
getch(); // library function to hold an output screen
}
Q. Program for Adding two integer number:
#include<stdio.h> //header file included for standard input output
#include<conio.h> //header file included for console input output
void main() // main function
{
int num1=2; // 2 is assigned to integer variable num1
int num2=6; // 6 is assigned to integer variable num2
int sum; // variable declared to store sum
sum = num1 + num2; // num1 & num2 value is added and store to sum
printf("The Sum=%d", sum); //value of sum is displayed
getch(); // library function to hold an output screen
}
Labels: Basic Syntax of C Programming:
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home