-->

struct initialization

in turboc++
------------------------------------------------------------------------------
//struct initialization
#include <stdio.h>
#include<string.h>
struct onl
{
    int a;
    float b;
    char name[30];
}var;
int main()
{
     var.a=98;
     var.b=5.4;
    strcpy(var.name,"raman");
    printf("a=%d\n",var.a);
     printf("b=%f\n",var.b);
     printf("name=%s",var.name);
    return 0;
}
/*note:
We donot need to use strcpy()if we use initialization
in same line as the var is.
same we can apply in union as well.
*/

concept of register storage

in turboc++
-------------------------------------------------------------------------------


//program to understand register variable .
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
void function();
int main()
{
    function();//function calling
    getch();
    return 0;
}
void function()//function body line
{

     register int a=4;//local variable, it can not be accessed from outsides and stored in RAM. We can store that in register location
    register float b=7.89;//local variable// can not be accessed from outsides stored in register
    printf("a=%d,b=%f",a,b);//printing value
}

/*note:
If we declare variable as register then it is stored in register and not not RAM. Its execution becomes faster.
*/


-------------------------------------------------------------------------------
in codeblocks:
-------------------------------------------------------------------------------------------
//program to understand register variable .
#include <stdio.h>
#include <stdlib.h>
void function();
int main()
{
    function();//function calling
    return 0;
}
void function()//function body line
{

     register int a=4;//local variable, it can not be accessed from outsides and stored in RAM. We can store that in register location
    register float b=7.89;//local variable// can not be accessed from outsides stored in register
    printf("a=%d,b=%f",a,b);//printing value
}

/*note:
If we declare variable as register then it is stored in register and not not RAM. Its execution becomes faster.
*/

concept of static storage

in turboc++
--------------------------------------------------------------------------------------
//program to understand static variable .
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
void function();
int main()
{
    function();//function calling
    function();
   getch();
    return 0;
}
void function()//function body line
{

     int a=4;//local variable, it can not be accessed from outsides. change this with static int a=4.

    printf("a=%d\n",a);//printing value
    a=a+1;
}
/* note:
It gives
a=4
a=4
where as it has to be 5 second time.
The computer can not retain its value on second calling.It loses its content (5) and prints same 4.

---------------------------
where as if we take static int a=4
the increased value remains there in memory untill the program is terminated.
We get
a=4
a=5
*/


-------------------------------------------------------------------------------------
in codeblocks:
-----------------------------------------------------------------------------------------------------
//program to understand static variable .
#include <stdio.h>
#include <stdlib.h>
void function();
int main()
{
    function();//function calling
    function();
    return 0;
}
void function()//function body line
{

     int a=4;//local variable, it can not be accessed from outsides. change this with static int a=4.

    printf("a=%d\n",a);//printing value
    a=a+1;
}
/* note:
It gives
a=4
a=4
where as it has to be 5 second time.
The computer can not retain its value on second calling.It loses its content (5) and prints same 4.

---------------------------
where as if we take static int a=4
the increased value remains there in memory untill the program is terminated.
We get
a=4
a=5
*/

External storage (also called global storage or variables:

in turboc++
-------------------------------------------------------------------------
//program to understand global variable .
#include <stdio.h>
#include <stdlib.h>
extern int a=5;// or simply int a //global variable; can be used with keyword extern
float b=4.5;//global variable;can be used with extern keyword
void function();
int main()
{
    printf("value of a and b from main function are=%d and %f\n",a,b);
    function();//function calling
    return 0;
}
void function()//function body line
{

        printf("from user defined function a=%d,b=%f\n",a,b);//printing value
}

















---------------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------
//program to understand global variable .
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
extern int a=5;// or simply int a //global variable; can be used with keyword extern
float b=4.5;//global variable;can be used with extern keyword
void function();
int main()
{
    printf("value of a and b from main function are=%d and %f\n",a,b);
    function();//function calling
    getch();
    return 0;
}
void function()//function body line
{

        printf("from user defined function a=%d,b=%f\n",a,b);//printing value
}

Automatic (also called local variables):

in turbo c++
-----------------------------------------------------------------------------
//program to understand local variable .
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
void function();
int main()
{
    function();//function calling
   getch();
    return 0;
}
void function()//function body line
{

    auto int a=4;//local variable, it can not be accessed from outsides. we can also use keyword auto.
    float b=7.89;//local variable// can not be accessed from outsides
    printf("a=%d,b=%f",a,b);//printing value
}







---------------------------------------------------------------------
in codeblocks
--------------------------------------------------------------------
//program to understand local variable .
#include <stdio.h>
#include <stdlib.h>
void function();
int main()
{
    function();//function calling
    return 0;
}
void function()//function body line
{

    auto int a=4;//local variable, it can not be accessed from outsides. we can also use keyword auto.
    float b=7.89;//local variable// can not be accessed from outsides
    printf("a=%d,b=%f",a,b);//printing value
}

WAp to concatenate two strings. Use no arguments and return its output.

in turboc++
-----------------------------------------------------------------------------------------------------------

//WAP to concatenate two  strings using(strcat()) function.Pass no parameters and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringcat();//prototype of function(must as pointer)
int main()
{
    printf("merged string=%s\n",stringcat());//prints with calling
     getch();
    return 0;
}
char *stringcat()
{
    char name[100],name1[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //first string input
    printf("enter second string\n");
    gets(name1);//second string input

   
    return strcat(name,name1);//returning the concatenated string
}









----------------------------------------------------------------------------------------------------------------
in codeblocks:
---------------------------------------------------------------------------------------------------
//WAP to concatenate two  strings using(strcat()) function.Pass no parameters and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringcat();//prototype of function(must as pointer)
int main()
{
    printf("merged string=%s\n",stringcat());//prints with calling
     getch();
    return 0;
}
char *stringcat()
{
    char name[100],name1[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //first string input
    printf("enter second string\n");
    gets(name1);//second string input

   
    return strcat(name,name1);//returning the concatenated string
}

WAP to get square root of a number using function.

in turboc++
----------------------------------------------------------------------------------------

//program to get  square root of a number using function.Use no argument and return some value
#include <stdio.h>  //header file
#include<math.h>
#include<conio.h>
 float square_root();//function prototype
int main()                 //main function
{
    printf("square root=%f",square_root());          // function calliing with output
    getch();
    return 0;             // returning 0 value
}

float square_root()      //function body line/definition
{
    float n,square;       // initilizating value 1
    printf("enter value");// display of those value
    scanf("%f",&n);
 
        square=sqrt(n);            // finding sum of two numbers
        return square;      //return of square
   
}










-------------------------------------------------------------------------
in codeblocks
--------------------------------------------------------------------------------------------------
//program to get  square root of a number using function.Use no argument and return some value
#include <stdio.h>  //header file
#include<math.h>
#include<conio.h>
 float square_root();//function prototype
int main()                 //main function
{
    printf("square root=%f",square_root());          // function calliing with output
    getch();
    return 0;             // returning 0 value
}

float square_root()      //function body line/definition
{
    float n,square;       // initilizating value 1
    printf("enter value");// display of those value
    scanf("%f",&n);
 
        square=sqrt(n);            // finding sum of two numbers
        return square;      //return of square
   
}