× Home Tokens ↓ Keywords Identifier Constant String Literal Symbols
Next Lec → ← Previous Lec

Basic Syntax of a C Program

From here we will learn basic building blocks by which we make C program

Tokens

Keywords

  • Keywords are reserved words in any programming language.
  • In C programming language there are 32 general purpose keywords
  • means these words can't be used as constant, variables
  • Example → return, int

32 General keywords

auto, double, int, struct, break, else, long, switch, case, enum, register, typedef, char, extern, return, union, const, float, short, unsigned, continue, for, signed, void, default, goto, sizeof, volatile, do, if, static, while

Identifier

  • Identifiers are names given to variables or functions in order to differentiate them from one another.
  • They are solely based on our choice but there are few rules that we have to follow while naming identifiers.
  • According to the rules the name can not contain special symbols such as @, - , *, < , etc.
  • Note: C is a case sensitive language so an identifier containing a capital letter and another one containing a small letter at the same place will be different.
  • For example the three words: Code, code and cOde can be used as three different identifiers.

Constant

  • Constant are very similar to variable and their values can be of any data type.
  • The only difference between constant and variable is that a constant's value never changes.

String literal

  • String literal or string constant is a line of characters enclosed by double quotes.
  • printf is used to print string literal onto the screen.

Symbols

  • Symbols are special characters reserved to perform certain actions.
  • They are used to notify the compiler so they can perform specific tasks on the given data.
  • Let's talk a little about white space. White space or blank space does not create any difference while using C.
    • Unlike Python where we have to press enter to go to new line, in C we use semi-colon (;) to end a line of code.
  • So until a semi colon arrives, the compiler will treat the code as a single liner so no matter how many lines we consume the code will run accurately if written correctly.
  • There are two code snippets given below. You can notice that they differ a lot regarding while space but their execution will show the same output onto the screen i.e. “Hello World”.
                        

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

                            #include <stdio.h>

                            int main()
                             {
                                printf
                                (
                                  "Hello World\n"
                                );
                                return 0;
                            }