Showing posts with label Asked in TCS. Show all posts
Showing posts with label Asked in TCS. Show all posts

Sunday, 5 July 2015

C Programs asked in TCS


Program:

#include<stdio.h>
#include<conio.h>
int main( )
{
       enum status
       {
              pass,fail,dist
        };
        enum status student1, student2, student3;
        student1 = pass;
        student2 = dist;
        student3 = fail;
        printf("%d,%d,%d",student1,student2,student3);
        return 0;
}

Output:


0,2,1



Monday, 20 October 2014

C program to Print the following Output

1 2 3 4 5 6 7 7 7 8 9 10

Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
          int i,j;
          for(i=1;i<=10;i++)
          {
                     if(i==7)
                     {
                              for(j=1;j<=3;j++)
                              {
                                          printf("%d  ",i);
                               }
                       }
                       printf("%d  ",i);
            }
}


Input/Output:

1 2 3 4 5 6 7 7 7 8 9 10



Tuesday, 19 August 2014

What are the different Storage Classes in C language


Storage Classes:

                   Storage Classes specify the characteristic properties of the memory location where memory is allocated for that variable.

--> C Language Provide four types of storage classes as follows.
1) Auto Storage Class
2) Static Storage Class
3) Extern Storage Class
4) Register Storage Class

1)Auto Storage Class:

--> Here memory is allocated and de-allocated automatically based on scope of the variable.
--> When the control enters to the scope, memory is allocated.
--> When the control runs out of the scope, memory is de-allocated automatically.
--> So, scope of an automatic variable will be only for the block in which it is contained and it's time will be only for the execution of that block/function.

                                       Keyword:  auto

--> When we don't specify any storage class, then by default is auto. 

2)Static Storage Class:

--> It is useful when we are required to retain the values of variables even after coming out of the function.
--> for the static variables, memory is allocated only once when the program starts the execution and will be de-allocated when execution of the program is complete. 
--> So, scope of a static variable will be only for the function in which it is contained, where as life time will be throughout the execution of the program.

                                     Keyword : static

--> static variable assume a value of  "0"(zero) by default, we can also assign our interested value as required.

3)Extern Storage Class:

--> This is useful when different files in a project are required share/access a common variable.

                                    Keyword: extern

--> Only global variables can be declared as extern variables.

4)Register Storage Class:

--> It is useful when we are required to store the variable specified in a CPU register.

                                      Keyword: register