C BASIC SYNTAX
C BASIC SYNTAX
Like every other language, ‘C’ also has its own character set. A program is a set
of instructions that, when executed, generate an output. The data that is
processed by a program consists of various characters and symbols. The output
generated is also a combination of characters and symbols.
• Letters
- Uppercase characters (A-Z)
- Lowercase characters (a-z)
• Numbers
- All the digits from 0 to 9
• Special characters
- White spaces (blank spaces)
- Blank space
- New line
- Carriage return
- Horizontal tab
• Special characters
What is Token in C?
Token is the smallest unit in a ‘C’ program, are the basically the building blocks
of a C program. It is each and every meaningful character, word and symbol that
you come across in your C program.
The compiler breaks a program into the smallest possible units (Tokens) and
proceeds to the various stages of the compilation.
Keywords have fixed meanings, and the meaning cannot be changed. There are
a total of 32 keywords in ‘C’. Keywords are written in lowercase letters.
do if Static while
An identifier is nothing but a name assigned to an element in a program.
Example, name of a variable, function, etc.
3
4. It should not contain any whitespace character.
5. The name must be meaningful.
After the compilation process, the linker will combine different object files and
creates a single executable file to run the program. The following diagram
shows the execution of a ‘C’ program
Nowadays, various compilers are available online, and you can use any of those
compilers. The functionality will never differ and most of the compilers will
provide the features required to execute both ‘C’ and ‘C++’ programs and most
of them are IDEs.
Following is the list of popular compilers available online:
i. Clang compiler
ii. Dev C
iii. MinGW compiler (Minimalist GNU for Windows)
iv. Portable ‘C’ compiler v. Turbo C vi. Code::Blocks
4
Basic Syntax of C Program
The basic syntax of the C program consists of the header, main() function, body,
and return type of the program. The C program can also be called a collection of
various tokens.
Header files (a.k.a Library files) contain a bunch of files that help the user to
include the predefined functions in C program according to his requirements.
You can add header files using the preprocessor directive #include.
Line 2: A blank line. C ignores white space. But we use it to make the code
more readable.
We can represent the main function in various forms, such as main(), int
main(), void main(), main(void), void main(void) and int main(void)
C Statement
Semicolon (;)
A semicolon (;) is used to mark the end of a statement and the beginning of
another statement in the C language.
The absence of a semicolon at the end of any statement will mislead the
compiler to think that this statement is not yet finished, sometimes may lead to
a compilation(syntax) error.
1. #include <stdio.h>
2. int main() {
3. printf("Hello,World")
4. return 0;
5. }
Output
Block
A block in C is a set of statements written within the opening and closing curly
brackets {……………}.
6
Adding Comments to Code
1. /*
2. This is my first program.
3. I am very excited!
4. */
5. #include <stdio.h>
6. int main(){
7. // Printing Hello World
8. printf("Hello,World");
9. // printf("Comment C Program");
10. return 0;
11. }
Chapter FAQs
Here are some frequently asked questions related to the C language syntax.