C - Basic Syntax


You have seen the essential structure of a programme, thus it'll be straightforward to grasp alternative basic building blocks of the C artificial language.

Tokens in C
A programme consists of assorted tokens and a token is either a keyword, AN symbol, a constant, a string literal, or an emblem. for instance, the subsequent C statement consists of 5 of 5

Printf(“Hello World\n”);


Individual Tokens

Printf
(
“Hello,world \n”
)
;


Semicolons
In a programme, the punctuation mark could be a statement slayer. That is, every individual statement should be all over with a punctuation mark. It indicates the top of 1 logical entity.

Given below square measure 2 totally different statements −

Printf(“Hello World \n”);
return 0;



Comments
Comments ar like serving to text in your program and that they ar unheeded by the compiler. they begin with /* and terminate with the characters */ as shown below −

/* My first program */



You cannot have comments inside comments and that they don't occur inside a string or character literals.

Identifiers
A C symbol may be a name accustomed determine a variable, function, or the other user-defined item. Associate in Nursing symbol starts with a letter A to Z, a to z, or Associate in Nursing underscore '_' followed by zero or a lot of letters, underscores, and digits (0 to 9).

C doesn't enable punctuation characters like @, $, and a pair of inside identifiers. C may be a case-sensitive programing language. Thus, men and men ar 2 completely different identifiers in C. Here ar some samples of acceptable identifiers −

mohd          zara        abc       move_name         a_123
mynamemike         j       _ temp    a23b9        retVal



Keywords

The following list shows the reserved words in C. These reserved words may not be used as constants or variables or any other identifier names.
auto
else
long
Switch
break
enum
register
Typedef
case
extern
return
Union
char
float
short
unsigned
const
for
signed
Void
continue
goto
sizeof
Volatile
default
if
static
While
do
Int
struct
_Packed
double





Whitespace in C
A line containing solely whitespace, presumably with a comment, is understood as a blank line, and a compiling program wholly ignores it.

Whitespace is that the term utilized in C to explain blanks, tabs, newline characters and comments. Whitespace separates one a part of a press release from another and permits the compiler to spot wherever one part during a statement, like int, ends and also the next part begins. Therefore, within the following statement −

int age;
there should be a minimum of one whitespace character (usually a space) between int and age for the compiler to be able to distinguish them. On the opposite hand, within the following statement −

fruit = apples + oranges;   // get the overall fruit
no whitespace characters area unit necessary between fruit and =, or between = and apples, though you're unengaged to embody some if you would like to extend readability.

Post a Comment

0 Comments