You are on page 1of 17

PROGRAM1.

1
2
3
4
Programming ‘class’ {
5
6
[For Beginners]
7
8 < BY >
9 < K.THARUN VIVEKANANDA >
10 < C.E.O >
11
12
13 }
14

C Language
PROGRAM1.C

1
2 Data types in C language:-
3
4
{
5
6
7  There are four types of data
8 types in C language.
9
10
11
12
13
14
}

C Language
PROGRAM1.C

1
2
What‘Data Types’?;
3
4
5
6
7
8
9
10
11
12
13
14

C LANGUAGE
PROGRAM1.C

1
2
Keywords in ‘C’ Language:-
3  A keyword is a reserved word. You cannot use it as a variable name,
4 constant name etc.
5  There are 32 keywords in C language as given below:
6
7
8
9
10
11
12
13
14

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’;
3
4  In C, there are different types of variables (defined
5
6
with different words),
7  for example:
8  Int - stores integers (whole numbers), without
9
10 decimals, such as 123 or -123.
11 Float - stores floating point numbers, with decimals,
12
13
such as 19.99 or -19.99.
14 Char - stores single characters, such as 'a' or 'B'.
C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ rules;
3
4 Rules for defining variables:-
5
6
 A variable can have alphabets, digits, and underscore.
7
8
 A variable name can start with the alphabet, and underscore only.
9 It can’t start with a digit.
10  No whitespace is allowed within the variable name.
11  A variable name must not be any reserved word or keyword, e.g.
12 int, goto, etc.
13
14

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
3
4
5
6 ∗ Types of Variables in C 
7 ∗ 1. Local Variable: A variable that is declared and used inside the
8 function or block is called a local variable. It is scope is limited to
9
function or block. It cannot be used outside the block. Local
10
11
variables need to be initialized before use.
12
13
14

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
3
#include <stdio.h>
4
5
void function( )
6 {
7 int x = 10; // local variable
8 }
9
10
int main()
11
12
{
13 function();
14 }

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
3
4
5
6 2. Global Variable: A variable that is declared outside the function
7 or block is called a global variable. It is declared at the start of the
8 program. It is available for all functions. 
9
10
11
12
13
14

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
3 #include <stdio.h>
4 int x = 20; //global variable
void function1()
5 {
6 printf("%d\n" , x);
7 }
8 void function2()
{
9
printf("%d\n" , x);
10 }
11 int main() {
12 function1();
function2();
13
return 0;
14 }

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
3
4
5
6 3. Static Variable: A variable that retains its value between multiple
7
function calls is known as a static variable. It is declared with the
8
9
static keyword.
10
11
12
13
14

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
#include <stdio.h>
3 void function(){
4 int x = 20;//local variable
5 static int y = 30;//static variable
6 x = x + 10;
y = y + 10;
7
printf("\n%d,%d",x,y);
8 }
9 int main() {
10
function();
11
function();
12 function();
13 return 0;
14 }

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
3
4
5
6
7
4. Automatic Variable: All variables in C that are declared inside
8 the block, are automatic variables by default. We can explicitly
9 declare an automatic variable using the auto keyword. Automatic
10 variables are similar to local variables. 
11
12
13
14

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
3
4 #include <stdio.h>
5 void function()
6 {
int x=10;//local variable (also automatic)
7
auto int y=20;//automatic variable
8 }
9 int main() {
10
function();
11
return 0;
12 }
13
14

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
3
4
5
6 5. External Variable: External variables can be shared between
7 multiple C files. We can declare an external variable
8 using extern keyword. 
9
10
11
12
13
14

C LANGUAGE
PROGRAM1.C

1
2
C ‘variable’ types;
3
myfile.h
4 extern int x=10;//external variable (also global)
5
6 program1.c
7 #include "myfile.h"
8
9 #include <stdio.h>
10
void printValue()
11
12 {
13
printf("Global variable: %d", global_variable);
14
}
C LANGUAGE
PROGRAM1.c

1
2
3
4
Programming ‘class’ {
5
6
7
8
9 Printf(“ THE END ”);
10
11
12
13 }
14

C Language

You might also like