C – Program Code – Basics Part I

C – Program Code – Basics

  1. Comments

e.g. /* ----anything ---*/

 

  1. Every statement end with a semicolon (;)

e.g. printf(“Hello World”);

 

  1. Block  Diagram

main()

{

…..

Statements;

……

}

 

  1. C – main function
  1. main()
  2. int main()
  3. void main()
  4. main(void)
  5. void main(void)
  6. int main(void)

 

  1. void means function does not return any value
  2. #define is a pre-processor compiler directive and not a statement

#define should not end with semicolon
placed at the beginning before main() function

  1. Two or more values declared using comma

e.g. int a, b, c;

  1. #include – directive to import the necessary header files (library functions)
    #include <stdio.h>

     
  2. Variables that are used in more than one function, are declared outside of all functions known as  Global Declaration Section and the variables known as global variables.
  3. main() function contains 1. Declaration part 2. Executable part
  4. Sub program section contains user defined functions
  5. C – free form language – i.e., compiler does not care, where on the line we begin typing.
  6. In C, lowercase letters are significant
  7. main() is the function where the program begins its execution
  8. File extensions :
    *.c – C – Program Source code
    *.o – Object Code (Unix), *.obj – Object Code (Windows)

*.out – Executable (Unix), *.exe – Executable (Windows)

 

  1. Trigraph Characters

Many non- English keyboards do not support all the special characters mentioned in C Character set, C introduces the concept of “trigraph” sequences to provide a way to enter certain characters that are not available on some keyboards. Each trigraph sequence consists of three characters (tow question marks followed by another character).

e..g.

??=

#

??(

[

??)

]

??<

{

??>

}

??!

|

??-

~

 

  1. In a C program the smallest individual units are known as C tokens.
  2. 6 type of tokens
  1. Keywords (float, while)
  2. Identifiers (main, total)
  3. Constants (3.14, 100)
  4. Strings (“abc”, “test”)
  5. Operators (+-*)
  6. Special Symbols ([]{})

 

  1. C Keywords

 

C89 has 32 keywords (reserved words with special meaning):


auto

break

case

char

const

continue

default

do

double

else

enum

extern

float

for

goto

if

int

long

register

return

short

signed

sizeof

static

struct

switch

typedef

union

unsigned

void

volatile

while


C99 adds five more keywords:


_Bool

_Complex

_Imaginary

inline

restrict


C11 adds seven more keywords:[16]


_Alignas

_Alignof

_Atomic

_Generic

_Noreturn

_Static_assert

_Thread_local


  1. C11 – Latest revision of C published on December 8, 2011

Informally called as C1X

It includes type generic macros, anonymous structures, improved Unicode support, atomic operations, multi-threading, and bounds-checked functions. It also makes some portions of the existing C99 library optional, and improves compatibility with C++.

  1. Rules for Identifiers
  1. First character must be an alphabet (or underscore)
  2. Must consist of only letters, digits or underscore
  3. Only first 31 characters are significant
  4. Cannot use a keyword
  5. Must not contain white space