Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Programming Methodology UNIT 3

The document provides a comprehensive overview of the C programming language, including its history, variable definitions, basic commands, and structure of C programs. It details the character set, data types, symbolic constants, and the components of a C program. Additionally, it outlines the steps for writing and executing a C program, along with examples and rules for variable naming.

Uploaded by

mathikavimass123
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programming Methodology UNIT 3

The document provides a comprehensive overview of the C programming language, including its history, variable definitions, basic commands, and structure of C programs. It details the character set, data types, symbolic constants, and the components of a C program. Additionally, it outlines the steps for writing and executing a C program, along with examples and rules for variable naming.

Uploaded by

mathikavimass123
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

UNIT – 2

4 Marks
1. Write down about the History of C language?
• C is a procedural programming language.
• It was developed by Dennis Ritchie in the year 1972.
• It was mainly developed as a system programming language to write an operating system.
•C is a case-sensitive language.
• The Unix operating system and virtually all Unix applications are written in the C language.
• C is a successor of B language which was introduced around 1970
• The language was formalized in 1988 by the American National Standard Institute (ANSI).
• By 1973 UNIX OS almost totally written in C.
• Today C is the most widely used System Programming Language.

2. How to define a variable in C? Explain with Syntax and Example.


A variable definition tells the compiler where and how much storage to create for the variable.
A variable definition specifies a data type and contains a list of one or more variables of that
type as follows −
type variable_list;
Here, type must be a valid C data type including char, w_char, int, float, double, bool, or any
user-defined object; and variable_list may consist of one or more identifier names separated
by commas.
Some valid declarations are shown here −
int i, j, k;
char c, ch;
float f, salary;
double d;
The line int i, j, k; declares and defines the variables i, j, and k; which instruct the compiler
to create variables named i, j and k of type int.
Variables can be initialized (assigned an initial value) in their declaration.
The initializer consists of an equal sign followed by a constant expression as follows −
type variable_name = value;
Some examples are −
extern int d = 3, f = 5; // declaration of d and f.
int d = 3, f = 5; // definition and initializing d and f.
byte z = 22; // definition and initializes z.
char x = 'x'; // the variable x has the value 'x'.
3. Explain about C basic commands with simple basic C program.
Explanation
C Basic commands
This command includes
#include <stdio.h> standard input output Header
File (stdio.h) from the C
library before compiling a C
program
It is the main function from
int main()
where C program execution
begins.
{ Indicates the beginning of the main function.
Whatever written inside this
/*_some_comments_*/ command “/* */” inside a C
program, it will not be
considered for compilation and
execution.
printf(“Hello_World! “); This command prints the output on the screen.
This command is used for any
getch();
character input From
keyboard.
This command is used to
return 0;
terminate a C program (main
function) and it returns 0.
It is used to indicate the
}
end of the main
function.

4. Discuss about the basic structure of C program.


5. Write down keypoints to be followed while writing a C program and Steps involving ton execute a
program.
Key Points:
• Each C programming statement is ended with semicolon (;) which are referred as statement
terminator.
• A header file is a file with extension .h which contains C function declarations and macro
definitions to be shared between several source files.
• Printf() command is used to print the output onto the screen.
• C programs are compiled using C compilers and displays output when executed.
• The C programs are writen into text files with extension ".c" , Ex. First.c
• To run “c” program you need to compile that program using a C Compiler which converts
your program into a language understandable by a computer.
• Many compilers are available for executing programs written in 'C'.
• A compiler compiles the source file and generates an object file.
• A linker links all the object files together and creates one executable file.
Example : AMPC, CCS C Compiler, ch, clang, Cygwin, Digital mars, GCC compiler,
MikroC Compiler, Portable C Compiler, Power C, QuickC, Ritchie C Compiler, Small-C
Steps to Write C Programs and Get the Output:
This is common to all C program
• Create
• Compile
• Execute or Run
• Get the Output
6 MARKS
1. Explain in detail about the C Character set

Alphabets
Alphabets has a two case.

1. Upper case A-Z

ASCII CODE: A=65 to Z=90

2. Lower case a-z.

ASCII CODE: a=97 to z=122

Digit
C programming support 10 digit which are used to construct numerical value.

 Digit 0-9.
 ASCII CODE: 0=48 to 9=57

Special character
C programming supports set of special symbols that include symbols to perform mathematical
operation, check condition and other special symbol.

 Special character %,&,*,etc.

White space
In computer programming, white space is a character that represent vertical space in
typography.

 White space \b,\v,\? and so on.

White Space Meaning White Space


\b blank space \\
\t horizontal tab \’
\v vertical tab \”
\r carriage return \?
\f form feed \0
\n new line \a
2. What is variable in C program? Write down the rules for defining the variables.

 A variable is a name of the memory location. It is used to store data. Its value can be
changed, and it can be reused many times.
 It is a way to represent memory location through symbol so that it can be easily
identified.
 Let's see the syntax to declare a

variable: type variable_list;

Rules for defining variables

o A variable can have alphabets, digits, and underscore.


o A variable name can start with the alphabet, and underscore only. It can't start with a
digit.
o No whitespace is allowed within the variable name.
o A variable name must not be any reserved word or keyword, e.g. int, float, etc.

Valid variable names:

1. int a;
2. int _ab;
3. int a30;

Invalid variable names:

1. int 2;
2. int a b;
3. int long;
3. What is Data type ? Explain in detail about basic and derived data type.

 A data type in C refers to the type of data used to store the information.
o For example, the name of a person would be an array of characters, while the
age will be in integers.
o Whereas, the marks of a student would require a data type that can store decimal
values.
1. Basic Data Types:

The basic data types are integer-based and floating-point based. C language supports both
signed and unsigned literals.

The memory size of the basic data types may change according to 32 or 64-bit operating
system.

Let's see the basic data types. Its size is given according to 32-bit architecture.

Data Types Memory Size Range

char 1 byte −128 to 127

signed char 1 byte −128 to 127

unsigned char 1 byte 0 to 255

short 2 byte −32,768 to 32,767

signed short 2 byte −32,768 to 32,767

unsigned short 2 byte 0 to 65,535

int 2 byte −32,768 to 32,767

signed int 2 byte −32,768 to 32,767

unsigned int 2 byte 0 to 65,535

short int 2 byte −32,768 to 32,767

signed short int 2 byte −32,768 to 32,767

unsigned short int 2 byte 0 to 65,535

long int 4 byte -2,147,483,648 to 2,147,483,647

signed long int 4 byte -2,147,483,648 to 2,147,483,647

unsigned long int 4 byte 0 to 4,294,967,295

Float 4 byte

Double 8 byte

long double 10 byte


2. Derived Data Types:

The primitive or basic data types are used to store single values
of different forms, but what if you need to store more values of
the same data type? Here, derived data types allow you to
combine the basic data types and store multiple values in a
single variable.

Derived data types are defined by the user itself, which means
that you can aggregate as many elements of similar data types
as required. There are four types of derived data types:

 Array
 Pointer
 Structure
 Union

Array:

 An array is a collection of similar data-type elements stored in a


contiguous memory location.

 For example, you can store float values like the marks of a
student, integer values like the roll number, and so on.

Pointer:

 Pointer is a variable used to store the address of another


variable. To store the address of a variable, the pointer
variable should be of the same data type.

 Pointer enables a user to perform dynamic memory


allocation in C language and also pass variables by
reference, which means that the user can pass the pointer
having the address of the variable.

 A pointer with no address is known as the null pointer,


while a pointer with no data type is called a void or
general-purpose pointer.
Structure:

 In C language, a structure is a user-defined data type, which is a


group of items used to store the values of similar or different data
types.

 For example, structures can be used to store information about a


student, including the name, the roll number, marks, and more. The
record of each student will be represented by an object of the
structure.

 A structure can be created inside as well as outside the main method.

 To define a structure, the keyword ‘struct’ is used as shown in the below program.

Union:

 Union is also a collection of elements with similar or different


data types, but the memory location is the same for all the
elements.

 It is a special kind of data type in C language, where you can


declare many variables, but only one variable can store the value at
a given time.

 Union is defined by the ‘union’ keyword, where each object will


represent a single record.

 The size of a union will be equal to the memory needed for the
largest variable inside it.

4. What are symbolic constants in C program and write the way for defining
symbolic constants with an Example.

 Symbolic constants in C programming are some symbols or labels that


hold a constant value during the program execution.
 The values of symbolic constants do not change during the program execution.

DEFINING SYMBOLIC CONSTANTS IN C:

In the C language, the symbolic constants are defined using the keyword #define.

Examples:

#define PI 3.141593
#define MAX 80

Above statements are preprocessor statements. When the program is


preprocessed, all the appearance of PI is replaced by the value
3.141593 and the appearance of MAX is replaced by 80.

Usually, in C programming symbolic constants are defined just above the main function.

#include <stdio.h> #define PI 3.141593 void main()


{
int radius = 6;
float area = PI * radius * radius; printf("The Area is : %f ",area);
}

In the above program, the value of the area is calculated as 3.141593 × 6 × 6.

5. How to declare a variable in C ? Explain with an Example.


 A variable declaration provides assurance to the compiler that
there exists a variable with the given type and name so that the
compiler can proceed for further compilation without requiring the
complete detail about the variable.
 A variable definition has its meaning at the time of compilation
only, the compiler needs actual variable definition at the time of
linking the program.
 A variable declaration is useful when you are using multiple files
and you define your variable in one of the files which will be
available at the time of linking of the program.
 You will use the keyword extern to declare a variable at any place.
 Though you can declare a variable multiple times in your C
program, it can be defined only once in a file, a function, or a
block of code.
Example
Try the following example, where variables have been declared at the top,
but they have been defined and initialized inside the main function –
#include <stdio.h>

// Variable declaration: extern int a, b;


extern int c; extern float f;

int main () {

/* variable definition: */ int a, b;


int c; float f;

/* actual initialization */ a = 10;


b = 20;

c = a + b;
printf("value of c : %d \n", c);

f = 70.0/3.0;
printf("value of f : %f \n", f);

return 0;
}
When the above code is compiled and executed, it produces the following result −
value of c : 30
value of f : 23.333334
The same concept applies on function declaration where you provide a
function name at the time of its declaration and its actual definition can be
given anywhere else. For example −

// function
declaration int func();

int main() {

// function
call int i =
func();
}

// function definition
int func() {
return 0;
}

10 Marks
1. Write in detail the various components of C program
Header Files:
The first and foremost component is the inclusion of the Header files in a C program.
• A header file is a file with extension .h
• Which contains C function declarations and macro definitions to be
shared between several source files.
Example of Header files:
 stddef.h – Defines several useful types and macros.
 stdint.h – Defines exact width integer types.
 stdio.h – Defines core input and output functions
 stdlib.h – Defines numeric conversion functions, pseudo-random
 network generator, memory allocation
 string.h – Defines string handling functions
 math.h – Defines common mathematical functions
Main Method:
The next part of a C program is to declare the main() function.
e.g. main()
{}
Variable declaration:
The next part of any C program is the variable declaration.
-In the C program, no variable can be used without being declared.
-Also in a C program, the variables are to be declared before any operation in the
function.
Ex. main()
{
int a;
Body of program:
Body of a function in C program, refers to the operations that are
performed in the functions. Example:
int main()
{
int x;
printf("%d", x); . .
Return Statement:
The last part in any C program is the return statement.
-The return statement refers to the returning of the values from a function.
-This return statement and return value depend upon the return type of the
function.
For example: if the return type is void, then there will be
no return statement.

2. Explain C Programming Basics to Write A C Program


C Basic commands Explanation
This command includes
#include <stdio.h> standard input output
Header File (stdio.h) from
the C library before
compiling a C program
It is the main function
int main()
from where C program
execution begins.
{ Indicates the beginning of the main
function.
Whatever written inside this
/*_some_comments_*/ command “/* */” inside a C
program, it will not be
considered for compilation
and execution.
printf(“Hello_World! “); This command prints the output on the
screen.
This command is used for
getch();
any character input From
keyboard.
This command is used to
return 0;
terminate a C program (main
function) and it returns 0.
It is used to indicate
}
the end of the main
function.

Steps to Write C Programs and Get the Output:


This is common to all C program
• Create
• Compile
• Execute or Run
• Get the Output
Key Points:
• Each C programming statement is ended with semicolon (;) which are
referred as statement terminator.
• A header file is a file with extension .h which contains C function
declarations and macro definitions to be shared between several source
files.
• Printf() command is used to print the output onto the screen.
• C programs are compiled using C compilers and displays output when executed.
• The C programs are writen into text files with extension ".c" , Ex. First.c
• To run “c” program you need to compile that program using a C
Compiler which converts your program into a language
understandable by a computer.
• Many compilers are available for executing programs written in 'C'.
• A compiler compiles the source file and generates an object file.
• A linker links all the object files together and creates one executable file.
Example : AMPC, CCS C Compiler, ch, clang, Cygwin, Digital mars,
GCC compiler, MikroC Compiler, Portable C Compiler, Power C,
QuickC, Ritchie C Compiler, Small-C

3. Explain the various features of C Programming Language


 Procedural Language
 Fast and Efficient
 Modularity
 Statically Type
 General-Purpose Language
 Rich set of built-in Operators
 Libraries with rich Functions
 Middle-Level Language
 Portability
 Easy to Extend.

Procedural Language:
 In a procedural language like C step by step predefined instructions are carried
out.
 C program may contain more than one function to perform a particular task.
 Most of the commonly used paradigm is an object-oriented programming
language.

Fast and Efficient:


 Newer languages like java, python offer more features than c programming
language but due to additional processing in these languages, their
performance rate gets down effectively.
 C programming language as the been middle-level language provides
programmers access to direct manipulation with the computer hardware but
higher-level languages do not allow this.
 That’s one of the reasons C language is considered the first choice to start
learning programming languages.
 It’s fast because statically typed languages are faster than dynamically typed
languages.

Modularity:
 The concept of storing C programming language code in the form of libraries
for further future uses is known as modularity.
 This programming language van does very little on its own most of its power
is held by its libraries.
 C language has its own library to solve common problems like in this we can
use a particular function by using a header file stored in its library.

Statically Type:
 C programming language is a statically typed language.
 Meaning the type of variable is checked at the time of compilation but not at run
time.
 This means each time a programmer type a program they have to mention the type
of variables used.

General Purpose Language:


 From system programming to photo editing software, the C programming language is
used in various applications.
 Some of the common applications where it’s used are as follows:
o Operating systems: Windows, Linux, iOS, Android, OXS
o Databases: PostgreSQL, Oracle, MySQL, MS SQL Server etc.

Rich set of built-in Operators:


It is a diversified language with a rich set of built-in operators which are used in
writing complex or simplified C programs.

Libraries with rich Functions:


Robust libraries and functions in C help even a beginner coder to code with ease.

Middle-Level Language:
As it is a middle-level language so it has the combined form of both capabilities of
assembly language and features of the high-level language.

Portability:
C language is lavishly portable as programs that are written in C language can run
and compile on any system with either none or small changes.

Easy to Extend: Programs written in C language can be extended means when a


program is already written in it then some more features and operations can be added
to it.

4. What is Tokens in C language and its Classifications in detail?

 Tokens in C is the most important element to be used in creating a program in C.


 We can define the token as the smallest individual element in C.
 For `example, we cannot create a sentence without using words; similarly, we cannot
create a program in C without using tokens in C.
 Therefore, we can say that tokens in C is the building block or the basic component
for creating a program in C language
 Classification of tokens in C
2. Keywords:

 Keywords are predefined, reserved words in C and each of which is associated with
specific features.
 These words help us to use the functionality of C language. They have special
meaning to the compilers.
 There are total 32 keywords in C.

Auto double int struct

Break else long switch

Case enum register typedef

Char extern return union

Continue for signed void

Do if static while

Default goto sizeof volatile

Const float short unsigned

3. Identifiers:

Each program element in C programming is known as an identifier.


They are used for naming of variables, functions, array etc.
These are user-defined names which consist of alphabets, number, underscore ‘_’.
Identifier’s name should not be same or same as keywords.
Keywords are not used as identifiers.
Rules for naming C identifiers −
 It must begin with alphabets or underscore.
 Only alphabets, numbers, underscore can be used, no other special characters,
punctuations are allowed.
 It must not contain white-space.
 It should not be a keyword.
 It should be up to 31 characters long.

Types of identifiers

o Internal identifier
o External identifier
Internal Identifier

If the identifier is not used in the external linkage, then it is known as an internal identifier.
The internal identifiers can be local variables.

External Identifier

If the identifier is used in the external linkage, then it is known as an external identifier. The
external identifiers can be function names, global variables.

1. int main()
2. {
3. int a=10;
4. int A=20;
5. printf("Value of a is : %d",a);
6. printf("\nValue of A is :%d",A);
7. return 0;
8. }

Output

Value of a is :10

Value of Ais:20

The above output shows that the values of both the variables, 'a' and 'A' are different.
Therefore, we conclude that the identifiers are case sensitive.

4. Strings:

A string is an array of characters ended with a null character(\0).

This null character indicates that string has ended. Strings are always enclosed with double
quotes(“ “).

Let us see how to declare String in C language −

char string[20] = {‘s’,’t’,’u’,’d’,’y’, ‘\0’};



 char string[20] = “demo”;
 char string [] = “demo”;
Here is an example of tokens in C language,

Example

#include >stdio.h> int main() {


// using keyword char char a1 = 'H';
int b = 8; float d = 5.6;
// declaration of string
char string[200] = "demodotcom"; if(b<10)
printf("Character
",a1);
else
printf("Float
",d);
printf("String
", string); return 0; Value : %c
}

value : %f

Value : %s

Output

Character Value : H
String Value : demodotcom

5. Operators

An operator is simply a symbol that is used to perform operations. There can be many types
of operations like arithmetic, logical, bitwise, etc.

There are following types of operators to perform different types of operations in C language.

o Arithmetic Operators
o Relational Operators
o Shift Operators
o Logical Operators
o Bitwise Operators
o Ternary or Conditional Operators
o Assignment Operator
o Misc Operator
6. Constants in C

A constant is a value assigned to the variable which will remain the same throughout the
program, i.e., the constant value cannot be changed.

There are two ways of declaring constant:

o Using const keyword


o Using #define pre-processor
o Types of constants in C

Constant Example

Integer constant 10, 11, 34, etc.

Floating-point constant 45.6, 67.8, 11.2, etc.

Octal constant 011, 088, 022, etc.

Hexadecimal constant 0x1a, 0x4b, 0x6b, etc.

Character constant 'a', 'b', 'c', etc.

String constant "java", "c++", ".net",


etc.

7. Special characters in C

Some special characters are used in C, and they have a special meaning which cannot be used
for another purpose.

o Square brackets [ ]: The opening and closing brackets represent the single and
multidimensional subscripts.
o Simple brackets ( ): It is used in function declaration and function calling. For
example, printf() is a pre-defined function.
o Curly braces { }: It is used in the opening and closing of the code. It is used in the
opening and closing of the loops.
o Comma (,): It is used for separating for more than one statement and for example,
separating function parameters in a function call, separating the variable when
printing the value of more than one variable using a single printf statement.
o Hash/pre-processor (#): It is used for pre-processor directive. It basically denotes
that we are using the header file.
o Asterisk (*): This symbol is used to represent pointers and also used as an operator
for multiplication.
o Tilde (~): It is used as a destructor to free memory.
o Period (.): It is used to access a member of a structure or a union.
o

5. What is variable in C program? Write down the rules for defining the variables. Explain in
detail about its types.

 A variable is a name of the memory location. It is used to store data. Its value can be
changed, and it can be reused many times.
 It is a way to represent memory location through symbol so that it can be easily
identified.
 Let's see the syntax to declare a

variable: type variable_list;

Rules for defining variables

o A variable can have alphabets, digits, and underscore.


o A variable name can start with the alphabet, and underscore only. It can't start with a
digit.
o No whitespace is allowed within the variable name.
o A variable name must not be any reserved word or keyword, e.g. int, float, etc.

Valid variable names:

1. int a;
2. int _ab;
3. int a30;

Invalid variable names:

1. int 2;
2. int a b;
3. int long;
Types of Variables in C

There are many types of variables in c:

1. local variable
2. global variable
3. static variable
4. automatic variable
5. external variable

Local Variable:

A variable that is declared inside the function or block is called a local variable.

It must be declared at the start of the block.

1. void function1(){
2. int x=10;//local variable
3. }
You must have to initialize the local variable before it is used.
Global Variable:

 A variable that is declared outside the function or block is called a global variable.
 Any function can change the value of the global variable. It is available to all the
functions.
 It must be declared at the start of the block

1. int value=20;//global variable


2. void function1(){
3. int x=10;//local variable
4. }
Static Variable:

 A variable that is declared with the static keyword is called static variable.
 It retains its value between multiple function calls.

1. void function1(){
2. int x=10;//local variable
3. static int y=10;//static variable
4. x=x+1;
5. y=y+1;
6. printf("%d,%d",x,y);
7. }
If you call this function many times, the local variable will print the same value for
each function call, e.g, 11,11,11 and so on. But the static variable will print the
incremented value in each function call, e.g. 11, 12, 13 and so on.
Automatic Variable

 All variables in C that are declared inside the block, are automatic variables by default.
 We can explicitly declare an automatic variable using auto keyword

1. void main(){
2. int x=10;//local variable (also automatic)
3. auto int y=20;//automatic variable
4. }
External Variable

 We can share a variable in multiple C source files by using an external variable.


 To declare an external variable, you need to use extern keyword.

myfile.h

1. extern int x=10;//external variable (also global)


program1.c

1. #include "myfile.h"
2. #include <stdio.h>
3. void printValue(){
4. printf("Global variable: %d", global_variable);
5. }

6. Define data types in C and explain in detail about its types.


 A data type in C refers to the type of data used to store the information.
o For example, the name of a person would be an array of characters, while the
age will be in integers.
o Whereas, the marks of a student would require a data type that can store decimal
values.
There are the following data types in C language.

Types Data Types

Basic Data Type int, char, float, double

Derived Data Type array, pointer, structure, union

Enumeration Data Type enum

Void Data Type void

3. Basic Data Types:

The basic data types are integer-based and floating-point based. C language supports both
signed and unsigned literals.

The memory size of the basic data types may change according to 32 or 64-bit operating
system.

Let's see the basic data types. Its size is given according to 32-bit architecture.

Data Types Memory Size Range

char 1 byte −128 to 127

signed char 1 byte −128 to 127

unsigned char 1 byte 0 to 255

short 2 byte −32,768 to 32,767

signed short 2 byte −32,768 to 32,767


unsigned short 2 byte 0 to 65,535

int 2 byte −32,768 to 32,767

signed int 2 byte −32,768 to 32,767

unsigned int 2 byte 0 to 65,535

short int 2 byte −32,768 to 32,767

signed short int 2 byte −32,768 to 32,767

unsigned short int 2 byte 0 to 65,535

long int 4 byte -2,147,483,648 to 2,147,483,647

signed long int 4 byte -2,147,483,648 to 2,147,483,647

unsigned long int 4 byte 0 to 4,294,967,295

Float 4 byte

Double 8 byte

long double 10 byte

4. Derived Data Types:

The primitive or basic data types are used to store single values of different
forms, but what if you need to store more values of the same data type? Here,
derived data types allow you to combine the basic data types and store multiple
values in a single variable.

Derived data types are defined by the user itself, which means that you can
aggregate as many elements of similar data types as required. There are four
types of derived data types:

 Array
 Pointer
 Structure
 Union

Array:

 An array is a collection of similar data-type elements stored in a contiguous memory


location.
 For example, you can store float values like the marks of a student, integer values
like the roll number, and so on.

Pointer:

 Pointer is a variable used to store the address of another variable. To store


the address of a variable, the pointer variable should be of the same data
type.

 Pointer enables a user to perform dynamic memory allocation in C


language and also pass variables by reference, which means that the user
can pass the pointer having the address of the variable.

 A pointer with no address is known as the null pointer, while a pointer with
no data type is called a void or general-purpose pointer.

Structure:

 In C language, a structure is a user-defined data type, which is a group of items used


to store the values of similar or different data types.

 For example, structures can be used to store information about a student, including the
name, the roll number, marks, and more. The record of each student will be
represented by an object of the structure.

 A structure can be created inside as well as outside the main method.

 To define a structure, the keyword ‘struct’ is used as shown in the below program.

Union:

 Union is also a collection of elements with similar or different data types, but the
memory location is the same for all the elements.

 It is a special kind of data type in C language, where you can declare many variables,
but only one variable can store the value at a given time.
 Union is defined by the ‘union’ keyword, where each object will represent a single
record.

 The size of a union will be equal to the memory needed for the largest variable inside
it.

5. Enumeration Data Type:

 Enumeration is a user-defined data type used to assign names to the integral constants
and enhance the readability of your program.

 The keyword used for enumeration is ‘enum’ with a syntax similar to

structure: Enum flaf{const1,const2,const3 };

There are two main reasons why enumerations are better than ‘#define’:

 Enum constants get default values by the compiler

 They can be declared in the local scope

6. Void Data Type:

 Void is a data type in C language that does not refer to any value of any type.

 It is mostly used as the return type in functions.

 You can declare the void pointers to take the address of variables from any data type.
These pointers are often called ‘generic pointers.

You might also like