C - Basic Syntax
C - Basic Syntax
so i have already seen the basic structure of a C program, so it will be easy to understand other basic building blocks of the C programming language its will be easy to understand.
TOKENS IN C
A programming token is the basic component of source code . C tokens are the basic buildings blocks in C language which are constructed together to write a C program.For example, the following C statement consists of SIX tokens
C tokens are of six types. They are,
- Keywords (eg: int, while),
- Identifiers (eg: main, total),
- Constants (eg: 10, 20),
- Strings (eg: “total”, “hello”),
- Special symbols (eg: (), {}),
- Operators (eg: +, /,-,*)
Semicolons
In a C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.
Given below are two different statement f("Hello, World! \n");
return 0;
Comments
Comments are just like helping text in your C program and they are ignored by the compiler. They start with /* and terminate with the characters */ as shown below −
/* my first program in C */
You cannot have comments within comments and they do not occur within a string or character
2. IDENTIFIERS IN C LANGUAGE:
- Each program elements in a C program are given a name called identifiers.
- Names given to identify Variables, functions and arrays are examples for identifiers. eg. x is a name given to integer variable in above program.
- Each program elements in a C program are given a name called identifiers.
- Names given to identify Variables, functions and arrays are examples for identifiers. eg. x is a name given to integer variable in above program.
An identifier starts with a letter A to Z, a to z, or an underscore '_' followed by zero or more letters, underscores, and digits (0 to 9).
C does not allow punctuation characters such as @, $, and % within identifiers. C is a case-sensitive programming language. Thus, Manpowerand manpower are two different identifiers in C. Here are some examples of acceptable identifiers −
mohd zara abc move_name a_123
myname50 _temp j 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.
- Keywords are pre-defined words in a C compiler.
- Each keyword is meant to perform a specific function in a C program.
- Since keywords are referred names for compiler, they can’t be used as variable name.
C language supports 32 keywords which are given below. Click on each keywords below for detail description and example programs.
auto | double |
int | struct |
const | float |
short | unsigned |
break | else |
long | switch |
continue | |
signed | void |
case | enum |
register | typedef |
default | goto |
sizeof | volatile |
char | extern |
return | union |
do | |
static | while |
Whitespace in C
A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it.
Whitespace is the term used in C to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Therefore, in the following statement −
int age;
fruit = apples + oranges; // get the total fruit
no whitespace characters are necessary between fruit and =, or between = and apples, although.
fruit = apples + oranges; // get the total fruit
no whitespace characters are necessary between fruit and =, or between = and apples, although.
Comments
Post a Comment