Monday, January 20, 2014

Examples for Datatypes


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Example for Primitive Datatypes in C  
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                       intvar.c

/* example for integer variable declaration */
# include <stdio.h>

main()
{
  int num = 100;
  printf("\nValue of num is %d", num);
  getch();
}

In this program,
we have declared a integer variable using the keyword 'int' . int is a primitive datatype
/* */ is a comment line and ignored by the compiler. Comment
lines are used for documenting the program which makes it more readable
* variables are declared in the beginning of the program
* the number of bytes allocated for a int variable is 2 bytes (32 bits) and it varies from compiler to compiler if the OS environment is different like Unix
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Monday, December 23, 2013

Our First C Program



---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is our first C program
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
              welcome.c

#include <stdio.h>
main()
{
   printf("\nWelcome to the world of C");
}

Before getting into minute details of the syntax, there are few points which you have to know about C programming.

* C is a compiler based language which means the whole program is translated into machine code before execution

* C language is case sensitive. This means main() and Main() are not the same

* Every C program must have a function called main()

* main() is a reserved word and cannot be MAIN() or Main()

* main() is a function and it is the first function to be executed in a C program

More about this program

# include ...as of now just note the point that it include the contents of another file at the beginning of the program

main() is a function

{} is a code block which has C syntax

printf() is a library function which displays the output.

There are lot more points to explain, but let me take you through step by step.