Showing posts with label c programming language. Show all posts
Showing posts with label c programming language. Show all posts

Saturday 17 March 2018

Structure in c programming


Structure in c programming:-

C supports following program structure

  1. Preprocessor Commands
  2. Functions
  3. Variables
  4. Statements & Expressions
  5. Comments

Lets start with simple code :-


        #include<stdio.h>

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

Note:-

#include<stdio.h> :-It is  a standard for input / output, which allows us to use some commands which includes a file called stdio.h


int/void main():-It is the main function where program execution begins.Each C program must contain only one main function.

Curly braces:-Two curly brackets "{.......}" are used to group all statements in the program.

printf():- It is a function in C, which displays text on the screen.


return 0:- It terminates the main() function and returns the value 0.

For more info click here


Wednesday 14 March 2018

Storage Classes in Cprogramming

A storage class repsents  the scope  and life-time of variables which helps programmers to define a particular variable during program's runtime.
These storage classes are preceded by the data type  There are 4 types of  storage class.

  1. auto
  2. register
  3. static
  4. extern
1 Auto:-  By default it  is associated  with all local variables as its storage class
eg:-
int  number;
or
auto int number;

2. Register:- It  is used to define local variables which will  be stored in a register instead of RAM. This means that the variable has a maximum size which is equivalent to the register size .
 it is used  to make program execution faster.
eg:-
register int  counter;

3.Static::- The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program. Static storage class has its scope local to the function in which it is define,
The keyword used to define this storage class is static.
eg:-
static int var = 9

4.Extern:- Variables that are declared outside of all functions are known as external variables. External or global variables are accessible to any function.

    It can be said that an extern variable is a global variable which is assigned with a value that can be accessed and used within the entire program.
eg:-
#include <stdio.h>

   int val;
  extern void funcGlobal();

main() 
{
   val = 15;
   funcGlobal();
}
For more info click here