Type Here to Get Search Results !

Web Stories

Basic Syntax of C Program

Dheeraj PatidarIn this article, I'm gonna discuss the Basic Syntax of the C Program in detail. Please read our previous article, where we discussed Environment Setup for C Program.

When we go to write any C Program there are a lot of concept come usually called basic syntax of c program which we need to understand in depth, because these tiny concepts make you perfect programmer.

let's understand the concept of syntax of C Program.


Basic Syntax of C Program

Following are some concepts of C Program syntax:

Semicolon in C Program

Semicolon play very important role in C Program. In order to terminate each of the statement in C Program we use Semicolon (;).

Semicolon is the special symbol in C program used after each of the statement of the program in order to terminate the statement.

The Absence of semicolon after any statement my generate a compilation error so we have to be aware about this character.

Example:

 
#include <stdio.h>
int main() {
   printf("Hello, World!")
   return 0;
}

In above C Program I haven't use semicolon after printf() function. so that the compiler wil notl consider next statement separately and we will get the compilation error as per the syntax rules.


Whitespace in C Program

Whitespace is also an another part of C program syntax. Whitespace refers to the space or tab before each of the statement. or words in a program statement

Whitespace is the term used in C to describe blanks, tabs, newline characters, and comments.

If we don't use whitespace where program need, then it may generate compilation or execution error.

Whitespace separates one part of a statement from another and helps the compiler to identify where one element in a statement, such as an int, ends and the next element begins.

So, we need to  take care of whitespace while writing a program. All programming languages strictly follow whitespaces.


Identifiers in C Programming Language

Identifiers basically refers to the name given to any variable, and function in a C Program.

Identifiers are sequence of characters, digits, and special characters.

In order to take name of any variable or function name we have to follow some syntax rules, are as follows:

  • The first character must be an alphabet or underscore(_).
  • No commas, blanks allow.
  • No special symbol other than underscore is allowed.
  • Variable names are case sensitive 
  • It should be less than 32 characters, which increases the portability in ANSI C.

Keywords in C Program

keywords are predefined reserved words in a programming language. 

These keywords help us to use the functionality of C programming. 

Due to C keywords special meaning we cannot be used them for other purpose. 

Following total 32 keyword are there in C programming:

auto

double

int

struct

break

else

long

switch

case

enum

register

typedef

char

extern

return

union

const

for

short

void

continue

float

signed

while

default

goto

sizeof

volatile

do

if

static

unsigned


Tokens in C Program

A C program consists of various tokens. A token is either a keyword, an identifier, a constant, a string literal, or a symbol. 

For example, the following C statement consists of 5 tokens:

 

printf("Hello, World! \n");


The Individual tokens are:

 

printf

(

   "Hello, World! \n"

)

;



Comments in C Program

Comments are like helping text in your C progra. They are ignored by the compiler. 

There are two type of comment in C Language:

  1. Single Line Comment
  2. Multi-Line Comment

A Single line comment is just writing double forward slashes before a statement, whereas Multiline Comment in c start with /* and terminate with the characters */.

Let's have a look in below example:

 

// my first C program

 

/* my first C Program

with www.dheerajpatidar.com

*/



Conclusion

So  In this article In have explained the Basic Syntax of C Programming Language and I hope you enjoy this Syntax of C Language article.

I will share you more articles in C Programming series, so keep in touch with this website regularly.


Thanks for Visit!



< Previous Post
  Next Post >
Different Parts of a C Program


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.