Wednesday, 7 January 2015

Basic Syntex In C language

Basic Syntex In C

I think you may have seen  my previous tutorial in c programming language and feel confident diving deep in programming. You may have confused where to start where to start learning programming.

Today I  will give   example and details  all about the basic syntax of C programming language including tokens, keywords, identifiers etc.Understanding the basic syntax of c programming  this  will help eliminate the syntax bugs even that confuse  the veteran C programmer. A simple syntax error can generate 100's of mystical compiler errors.



What does Semicolons ; in C

In C programming language a semicolon is the statement terminator.  Each individual statement of the program must be ended with a semicolon. It actually indicates the end of one logical entity or statement.
For example
printf("Hello everyone this is my first c program!");



What does mean Comments in C:

Comments are the text  that are ignored by the compiler. It is actually helping text  that help you to write good and understandable code


What does mean Identifiers in C

An identifier in c  is a name that compiler used to identify a variable, a  function, or   other user-defined  function or item).
An Identifier are created to give up unique name to C entities for example declare a variable in c. you may have question what is variable. I will discuss it later.

     int bananas;
     int monkey;
     int mango_tree;
here bananas is a identifier which denotes a variable of type integer in c

Rules for writing identifier  In C
1. An identifier can be composed of letters (both uppercase and lowercase letters), digits and underscore '_' only.
2. The first letter of identifier should be either a letter or an underscore. But, it is discouraged to start an identifier name with an underscore though it is legal. It is because, identifier that starts with underscore can conflict with system names. In such cases, compiler will complain about it. Some system names that start with underscore are _fileno, _iob, _wfopen etc.
3.  There is no rule for the length of an identifier. However, the first 31 characters of an identifier are discriminated by the compiler. So, the first 31 letters of two identifiers in a program should be different.


Tokens in C

In C programming language there various tokens. Token is either a keyword or an identifier, a string literal,  a constant, or a symbol. For example, the following C statement consists of five tokens:
Statement :   printf("Hello, World!");
Token no 1:   printf
Token no 2:   (
Token no 3:   "Hello, World! \n"
Token no 3:   )
Token no 5:   ;


Keywords in C


Now I am going to introduce the reserved key words in C


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





No comments:

Post a Comment