Computer Science, asked by parthkoshti4140, 10 months ago

What is the value of the variables in c just after declaration?

Answers

Answered by anupama777vidya
0

Answer:

Just after declaration,a variable gets garbage value.

Hope it helps...

Explanation:

Answered by sarimkhan112005
0

Explanation:

hey mate

i think you must have started the basics of c language

i am glad you asked

i am also a c and java student i also prefer you to use yashwant kanetkar book

so anyways here is your answer

________________________________________________________

RULES FOR NAMING C VARIABLE:

Variable name must begin with letter or underscore.

Variables are case sensitive

They can be constructed with digits, letters.

No special symbols are allowed other than underscore.

sum, height, _value are some examples for variable name

DECLARING & INITIALIZING C VARIABLE:

Variables should be declared in the C program before to use.

Memory space is not allocated for a variable while declaration. It happens only on variable definition.

Variable initialization means assigning a value to the variable.

THERE ARE THREE TYPES OF VARIABLES IN C PROGRAM THEY ARE,

Local variable

Global variable

Environment variable

1. EXAMPLE PROGRAM FOR LOCAL VARIABLE IN C:

The scope of local variables will be within the function only.

These variables are declared within the function and can’t be accessed outside the function.

In the below example, m and n variables are having scope within the main function only. These are not visible to test function.

Like wise, a and b variables are having scope within the test function only. These are not visible to main function.

C

#include<stdio.h>

void test();

int main()

{

  int m = 22, n = 44;

       // m, n are local variables of main function

       /*m and n variables are having scope

       within this main function only.

       These are not visible to test funtion.*/

       /* If you try to access a and b in this function,

       you will get 'a' undeclared and 'b' undeclared error */

  printf("\nvalues : m = %d and n = %d", m, n);

  test();

}

void test()

{

  int a = 50, b = 80;

       // a, b are local variables of test function

       /*a and b variables are having scope

       within this test function only.

       These are not visible to main function.*/

       /* If you try to access m and n in this function,

       you will get 'm' undeclared and 'n' undeclared

       error */

  printf("\nvalues : a = %d and b = %d", a, b);

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

#include<stdio.h>

void test();

 

int main()

{

  int m = 22, n = 44;

       // m, n are local variables of main function

       /*m and n variables are having scope

       within this main function only.

       These are not visible to test funtion.*/

       /* If you try to access a and b in this function,

       you will get 'a' undeclared and 'b' undeclared error */

  printf("\nvalues : m = %d and n = %d", m, n);

  test();

}

 

void test()

{

  int a = 50, b = 80;

       // a, b are local variables of test function

       /*a and b variables are having scope

       within this test function only.

       These are not visible to main function.*/

       /* If you try to access m and n in this function,

       you will get 'm' undeclared and 'n' undeclared

       error */

  printf("\nvalues : a = %d and b = %d", a, b);

}

COMPILE & RUN

 

OUTPUT:

values : m = 22 and n = 44

values : a = 50 and b = 80

EXAMPLE PROGRAM FOR GLOBAL VARIABLE IN C:

The scope of global variables will be throughout the program. These variables can be accessed from anywhere in the program.

This variable is defined outside the main function. So that, this variable is visible to main function and all other sub functions.

C

#include<stdio.h>

void test();int m = 22, n = 44;

int a = 50, b = 80;

int main()

{

  printf("All variables are accessed from main function");

  printf("\nvalues: m=%d:n=%d:a=%d:b=%d", m,n,a,b);

  test();

}

void test()

{

  printf("\n\nAll variables are accessed from" \

  " test function");

  printf("\nvalues: m=%d:n=%d:a=%d:b=%d", m,n,a,b);

}  

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

#include<stdio.h>

void test();int m = 22, n = 44;

int a = 50, b = 80;

 

int main()

{

  printf("All variables are accessed from main function");

  printf("\nvalues: m=%d:n=%d:a=%d:b=%d", m,n,a,b);

  test();

}

 

void test()

{

  printf("\n\nAll variables are accessed from" \

  " test function");

  printf("\nvalues: m=%d:n=%d:a=%d:b=%d", m,n,a,b);

}  

COMPILE & RUN

OUTPUT:

All variables are accessed from main function

values : m = 22 : n = 44 : a = 50 : b = 80

All variables are accessed from test function

values : m = 22 : n = 44 : a = 50 : b = 80

3. ENVIRONMENT VARIABLES IN C:

Environment variable is a variable that will be available for all C  applications and C programs.

We can access these variables from anywhere in a C program without declaring and initializing in an application or C program.

The inbuilt functions which are used to access, modify and set these environment variables are called environment functions.

There are 3 functions which are used to access, modify and assign an environment variable in C. They are,

1. setenv()

2. getenv()

3. putenv()

__________________________________________________________

hope it helps you

plz mark as brainliest

Similar questions