Docsity

VTU 1ST SEM PROGRAMMING IN C AND DATA STRUCTURES 14PCD13 NOTES, Study notes of C programming

Toggle sidebar
bg1
PROGRAMMING IN C AND DATA STRUCTURES
Code: 14PCD13/23 IA Marks: 25
Hrs/Week: 04 Exam Hrs: 03
Total Hrs: 52 Exam Marks:100
Objectives:
The objectives of this course is to make students to learn basic principles of Problem solving, implementing
through C programming language and to design & develop programming skills.
MODULE I
INTRODUCTION TO C LANGUAGE: Pseudocode solution to problem, Basic concepts of a C program,
Declaration, Assignment & Print statement, Types of operators and expressions, Programming examples and
exercise. Text 1: Chapter 2 Text 2: 1.1, 1.2, 1.3 10 Hours
MODULE II
BRANCHING AND LOOPING: Two way selection (if, if-else, nested if-else, cascaded if-else), switch statement,
ternary operator? Go to, Loops (For, do-while, while) in C, break and continue, programming examples and
exercises.
Text 1: Chapter 3 Text 2: 4.4 10 Hours
MODULE II
BRANCHING AND LOOPING: Two way selection (if, if-else, nested if-else, cascaded if-else), switch statement,
ternary operator? Go to, Loops (For, do-while, while) in C, break and continue, programming examples and
exercises.
Text 1: Chapter 3 Text 2: 4.4 10 Hours
MODULE III
ARRAYS, STRINGS AND FUNCTIONS:
ARRAYS AND STRINGS: Using an array, Using arrays with Functions, Multi-Dimensional arrays. String:
Declaring, Initializing, Printing and reading strings, strings manipulation functions, strings input and output
functions, arrays of strings, programming examples and Exercises.
Text 1: 5.7 Text 2: 7.3, 7.4 Chapter 9
FUNCTIONS: Functions in C, Argument Passing โ€“ call by value, Functions and program structure, location of
functions, void and parameter less Functions, Recursion, programming examples and exercises.
Text 1: 1.7, 1.8, Chapter 4 Text 2: 5.1 to 5.4 10 Hours
MODULE IV
STRUCTURES AND FILE MANAGEMENT: Basic of structures, structures and Functions, Arrays of structures,
structure Data types, type definition, Defining, opening and closing of files, Input and output operations,
programming examples and exercises.
Text 1: 6.1 to 6.3 Text 2: 10.1 to 10.4, Chapter 11 10 Hours
MODULE V
POINTERS AND PREPROCESSORS: Pointers and address, pointers and functions arguments, pointers and
arrays, address arithmetic, character pointer and functions, pointers to pointer ,Initialization of pointers arrays,
Dynamic allocations methods, Introduction to Preprocessors, Complier control Directives, programming examples
and exercises. Text 1: 5.1 to 5.6, 5.8 Text 2: 12.2, 12.3, 13.1 to 13.7
Introduction to Data Structures: Primitive and non primitive data types, Definition and applications of Stacks,
Queues, Linked Lists and Trees.
Text 2: 14.1, 14.2, 14.11, 14.12, 14.13, 14.15, 14.16, 14.17, 15.1 08 Hours + 04 Hours
TEXT BOOK:
1. Brain W. Kernighan and Dennis M. Richie: The C programming Language, 2nd Edition, PHI, 2012.
2. Jacqueline Jones & Keith Harrow: Problem Solving with C, 1st Edition, Pearson 2011.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64
Discount

On special offer

Partial preview of the text

Download VTU 1ST SEM PROGRAMMING IN C AND DATA STRUCTURES 14PCD13 NOTES and more Study notes C programming in PDF only on Docsity!

Code: 14PCD13/23 IA Marks: 25

Hrs/Week: 04 Exam Hrs: 03

Total Hrs: 52 Exam Marks:

Objectives: The objectives of this course is to make students to learn basic principles of Problem solving, implementing through C programming language and to design & develop programming skills.

MODULE I INTRODUCTION TO C LANGUAGE : Pseudocode solution to problem, Basic concepts of a C program, Declaration, Assignment & Print statement, Types of operators and expressions, Programming examples and exercise. Text 1: Chapter 2 Text 2: 1.1, 1.2, 1.3 10 Hours MODULE II BRANCHING AND LOOPING: Two way selection (if, if-else, nested if-else, cascaded if-else), switch statement, ternary operator? Go to, Loops (For, do-while, while) in C, break and continue, programming examples and exercises. Text 1 : Chapter 3 Text 2: 4.4 10 Hours

MODULE II BRANCHING AND LOOPING: Two way selection (if, if-else, nested if-else, cascaded if-else), switch statement, ternary operator? Go to, Loops (For, do-while, while) in C, break and continue, programming examples and exercises. Text 1: Chapter 3 Text 2: 4.4 10 Hours

MODULE III ARRAYS, STRINGS AND FUNCTIONS: ARRAYS AND STRINGS : Using an array, Using arrays with Functions, Multi-Dimensional arrays. String: Declaring, Initializing, Printing and reading strings, strings manipulation functions, strings input and output functions, arrays of strings, programming examples and Exercises. Text 1: 5.7 Text 2 : 7.3, 7.4 Chapter 9

FUNCTIONS : Functions in C, Argument Passing โ€“ call by value, Functions and program structure, location of functions, void and parameter less Functions, Recursion, programming examples and exercises. Text 1: 1.7, 1.8, Chapter 4 Text 2: 5.1 to 5.4 10 Hours

MODULE IV STRUCTURES AND FILE MANAGEMENT: Basic of structures, structures and Functions, Arrays of structures, structure Data types, type definition, Defining, opening and closing of files, Input and output operations, programming examples and exercises. Text 1: 6.1 to 6.3 Text 2 : 10.1 to 10.4, Chapter 11 10 Hours MODULE V POINTERS AND PREPROCESSORS: Pointers and address, pointers and functions arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer ,Initialization of pointers arrays, Dynamic allocations methods, Introduction to Preprocessors, Complier control Directives, programming examples and exercises. Text 1: 5.1 to 5.6, 5.8 Text 2: 12.2, 12.3, 13.1 to 13. Introduction to Data Structures : Primitive and non primitive data types, Definition and applications of Stacks, Queues, Linked Lists and Trees. Text 2: 14.1, 14.2, 14.11, 14.12, 14.13, 14.15, 14.16, 14.17, 15.1 08 Hours + 04 Hours

TEXT BOOK:

  1. Brain W. Kernighan and Dennis M. Richie: The C programming Language, 2nd^ Edition, PHI, 2012.
  2. Jacqueline Jones & Keith Harrow: Problem Solving with C, 1st Edition, Pearson 2011.

TABLE OF CONTENTS

  • MODULE I: INTRODUCTION TO C LANGUAGE 1-
  • MODULE II: BRANCHING & LOOPING 20-
  • MODULE III: ARRAYS & STRINGS 35- - FUNCTIONS 49-
  • MODULE IV: STRUCTURES & FILE MANAGEMENT 58-
  • MODULE V: POINTERS & PREPROCESSORS 65-
    • INTRODUCTION TO DATA STRUCTURES 77-
  • BASIC C PROGRAMS 90- WORKED EXAMPLES
  • C PROGRAMS BASED ON BRANCHING 94-
  • C PROGRAMS BASED ON LOOPING 98-
  • C PROGRAMS BASED ON ARRAYS 107-
  • C PROGRAMS BASED ON FUNCTIONS 117-
  • C PROGRAMS BASED ON STRUCTURES & FILE MGMT. 121-

BASIC CONCEPTS OF A C PROGRAM

  • The structure of a C program is shown below: preprocessor directives void main() { declaration section

statement-1 // Executable section starts statement- statement- statement-4 // Executable section ends } Preprocessor Directives

  • The preprocessor accepts the source program and prepare the source program for compilation.
  • The preprocessor-statements start with symbol #.
  • The normal preprocessor used in all programs is include.
  • The #include directive instructs the preprocessor to include the specified file-contents in the beginning of the program.
  • For ex: #include<stdio.h> main()
  • Every C program should have a function called as main().
  • This the first function to be executed always.
  • The statements enclosed within left and right brace is called body of the function. The main() function is divided into 2 parts: 1) Declaration Section
    • The variables that are used within the function main() should be declared in the declaration-section only.
    • The variables declared inside a function are called local-variables. Ex: int p, t, r; 2) Executable Section
    • This contains the instructions given to the computer to perform a specific task.
    • The task may be to โ†’ display a message โ†’ read data or โ†’ add 2 numbers etc
    • Comments are portions of the code ignored by the compiler. The comments allow the user to make simple notes in the source-code. // this is an example for single line comment /* this is an example for multiple line comment */ Example: Program to display a message on the screen. #include<stdio.h> void main() { printf(โ€œWelcome to Cโ€); } Output: Welcome to C

HOW TO LEARN C LANGUAGE?

  • English is a universal language used to communicate with others.
  • In the same way, C is a language used to communicate with computer. In other words, C is used to instruct computer to perform particular task.
  • The task can be โ†’ simple task like adding 2 numbers or โ†’ complex task like building a railway reservation system
  • Before you play the game, you should learn rules of the game. So that you can play better and win easily. In the same way, to write C programs, you should learn rules of C language.

STEPS TO LEARN C LANGUAGE Step 1: Before speaking any language, you should first learn alphabets. In the same way, to learn C language, you should first learn alphabets in C. Step 2: Then, you should learn how to group alphabets in particular sequence to form a meaningful word. In the same way, in C language, you should learn tokens (i.e. words). Step 3: Then, you should learn how to group the words in particular sequence to form a meaningful sentence. In the same way, in C language, you should learn instruction (i.e. sentence). Step 4: Then, you should learn how to group the sentences in particular sequence to form a meaningful paragraph. In the same way, in C language, you should learn program (i.e. paragraph).

CHARACTER SET

  • Character-set refers to the set of alphabets, letters and some special characters that are valid in C language.
  • For example, the characters in C are: โ†’ Letters A-X, a-z, both upper and lower โ†’ Digits 0- โ†’ Symbols such as + - * / % โ†’ White spaces

TOKENS

  • A token is a smallest element of a C program.
  • One or more characters are grouped in sequence to form meaningful words. These meaningful words are called tokens.
  • The tokens are broadly classified as follows โ†’ Keywords ex: if, for, while โ†’ Identifiers ex: sum, length โ†’ Constants ex: 10, 10.5, 'a', "sri" โ†’ Operators ex: + - * / โ†’ Special symbols ex: [], (), {}

CONSTANTS

  • A constant is an identifier whose value remains fixed throughout the execution of the program.
  • The constants cannot be modified in the program.
  • For example: 1, 3.14512 , โ€žzโ€Ÿ, โ€œvtunotesbysri"
  • Different types of constants are: 1) Integer Constant
    • An integer is a whole number without any fraction part.
    • There are 3 types of integer constants: i) Decimal constants (0 1 2 3 4 5 6 7 8 9) For ex: 0, -9, 22 ii) Octal constants (0 1 2 3 4 5 6 7) For ex: 021, 077, 033 iii) Hexadecimal constants (0 1 2 3 4 5 6 7 8 9 A B C D E F) For ex: 0x7f, 0x2a, 0x 2) Floating Point Constant
    • The floating point constant is a real number.
    • The floating point constants can be represented using 2 forms: i) Fractional Form
      • A floating point number represented using fractional form has an integer part followed by a dot and a fractional part.
      • For ex: 0.5, -0. ii) Scientific Notation (Exponent Form)
      • The floating point number represented using scientific notation has three parts namely: mantissa, E and exponent.
      • For ex: 9.86E3 imply 9.86*10^3 3) Character Constant
    • A symbol enclosed within a pair of single quotes(') is called a character constant.
    • Each character is associated with a unique value called an ASCII (American Standard Code for Information Interchange) code.
    • For ex: '9', 'a', '\n' 4) String Constant
    • A sequence of characters enclosed within a pair of double quotes(โ€œ) is called a string constant.
    • The string always ends with NULL (denoted by \0) character.
    • For ex: "9" "a" "sri" "\n" 5) Escape Sequence Characters
    • An escape sequence character begins with a backslash and is followed by one character.
    • A backslash () along with some characters give rise to special print effects by changing (escaping) the meaning of some characters.
    • The complete set of escape sequences are: Escape Sequences Character \b Backspace \f Form feed \n Newline \r Return \t Horizontal tab \v Vertical tab \ Backslash ' Single quotation mark " Double quotation mark ? Question mark \0 Null character

BASIC DATA TYPES

  • The data type defines the type of data stored in a memory-location.
  • C supports 3 classes of data types:
    1. Primary data type For ex: int, flaot
    2. Derived data types For ex: array
    3. User defined data types For ex: structure
  • C supports 5 primary data types: 1) int
    • An int is a keyword which is used to define integers.
    • Using int keyword, the programmer can inform the compiler that the data associated with this keyword should be treated as integer.
    • C supports 3 different sizes of integer: โ†’ short int โ†’ int โ†’ long int 2) float
    • A float is a keyword which is used to define floating point numbers. 3) double
    • A double is a keyword used to define long floating point numbers. 4) char
    • A char is a keyword which is used to define single character. 5) void
    • void is an empty data type. Since no value is associated with this data type, it does not occupy any space in the memory.
    • This is normally used in functions to indicate that the function does not return any value. Range of data types Data type Bytes Range of data type char 1 bytes -128 to 127 int 2 bytes -32, 768 to 32, float 4 bytes 3.4E-38 to 3.4E double 8 bytes 1.7E-308 to 1.7E

Qualifiers

  • Qualifiers alter the meaning of primary data types to yield a new data type. Size Qualifiers
    • Size qualifiers alter the size of primary data type.
    • The keywords long and short are 2 size qualifiers. For example: long int i; //The size of int is 2 bytes but, when long keyword is //used, that variable will be of 4 bytes short int i; //The size of int is 2 bytes but, when short keyword is //used, that variable will be of 1 byte Sign Qualifiers
    • Whether a variable can hold positive value, negative value or both values is specified by sign qualifiers.
    • Keywords signed and unsigned are used for sign qualifiers. unsigned int a; //unsigned variable can hold zero & positive values only signed int b; //signed variable can hold zero , positive and negative values Constant Qualifiers
    • Constant qualifiers can be declared with keyword const.
    • An object declared by const cannot be modified. const int p=20; //the value of p cannot be changed in the program.

DATA INPUT/OUTPUT FUNCTIONS

  • There are many library functions for input and output in C language.
  • For ex: getch( ), putchar( ), scanf( ), printf( )
  • For using these functions in a C-program there should be preprocessor statement #include<stdio.h>. Input Function
  • The input functions are used to read the data from the keyboard and store in memory-location.
  • For ex: scanf(), getchar(), getch(), getche(), gets() Output Functions
  • The output functions are used to receive the data from memory-locations and display on the monitor.
  • For ex: printf(), putchar(), putch(), puts() Types of I/O Functions
  • There are 2 types of I/O Functions as shown below:

UNFORMATTED I/O

getchar() and putchar()

  • getchar() is used to โ†’ read a character from the keyboard and โ†’ store this character into a memory-location
  • You have to press ENTER key after typing a character.
  • The syntax is shown below: char variable_name = getchar( );
  • For ex: char z; z= getchar( );
  • putchar() is used to display a character stored in the memory-location on the screen. #include<stdio.h> main() { char x; char y=โ€Ÿnโ€Ÿ; printf(โ€œenter one letter terminated by ENTER key \nโ€); x = getchar (); putchar (y); // same as printf(โ€œ%cโ€, z); } Output: enter one letter terminated by ENTER key m n

getch() and putch()

  • getch() is used to read a character from the keyboard without echo(i.e. typed character will not be visible on the screen). The character thus entered will be stored in the memory location.
  • putch() is used to display a character stored in memory-location on the screen. #include<stdio.h> void main() { int z; printf(โ€œenter one letter \n โ€); z = getch (); putch (z); // same as printf(โ€œ%cโ€, z) } Output: enter one letter m //m is not visible m getche()
  • getche() is used to read a character from the keyboard with echo(i.e. typed character will be visible on the screen). The character thus entered will be stored in the memory-location. #include<stdio.h> void main() { int z; printf(โ€œenter one letter \nโ€); z = getche (); putch( z); // same as printf(โ€œ%cโ€, z) } Output: enter one letter m //m is visible m gets() and puts()
  • gets() is used to โ†’ read a string from the keyboard and โ†’ store the string in memory-locations
  • puts() is used to display a string stored in memory-locations on the screen. #include<stdio.h> void main() { char string[20]; printf("enter a string \n"); gets (string); puts (string); // same as printf("%s", string); } Output: enter a string vtunotesbysri vtunotesbysri

Disadvantage of Unformatted I/O

  • It is not possible to read/print any other data except characters i.e. it is not possible to read/print integer numbers, floating point numbers etc.

VARIATIONS IN OUTPUT FUNCTION FOR INTEGER AND FLOATS

  • Integer and floating-points can be displayed in different formats in C as shown below: #include<stdio.h> void main() { printf("Case 1 :%6d \n",9876); // Prints the number right justified within 6 columns printf("Case 2 :%3d \n",9876); // Prints the number to be right justified to 3 columns but, there are 4 // digits so number is not right justified printf("Case 3 :%.2f \n",987.6543); // Prints the number rounded to two decimal places printf("Case 4: %.f \n",987.6543); // Prints the number rounded to 0 decimal place, i.e., rounded to integer printf("Case 5: %e ",987.6543); // Prints the number in exponential notation(scientific notation) } Output: Case 1: 9876 Case 2: Case 3:987. Case 4: Case 5:9.876543e+

OPERATOR

  • An operator can be any symbol like + - * / that specifies what operation need to be performed on the data.
  • For ex:
    • indicates add operation
    • indicates multiplication operation Operand
  • An operand can be a constant or a variable. Expression
  • An expression is combination of operands and operator that reduces to a single value.
  • For ex: Consider the following expression a+b here a and b are operands while + is an operator

CLASSIFICATION OF OPERATORS Operator Name For Example Arithmetic operators + - * / % Increment/decrement operators ++ -- Assignment operators = Relational operators < > == Logical operators && || ~ Conditional operator ?: Bitwise operators & | ^ Special operators []

ARITHMETIC OPERATORS

  • These operators are used to perform arithmetic operations such as addition, subtraction,
  • There are 5 arithmetic operators: Operator Meaning of Operator
    • addition
    • subtraction
    • multiplication / division % modulos
  • Division symbol (/) โ†’ divides the first operand by second operand and โ†’ returns the quotient. Quotient is the result obtained after division operation.
  • Modulus symbol (%) โ†’ divides the first operand by second operand and โ†’ returns the remainder. Remainder is the result obtained after modulus operation.
  • To perform modulus operation, both operands must be integers.
  • Program to demonstrate the working of arithmetic operators. #include<stdio.h> void main() { int a=9,b=4,c; c=a + b; printf("a+b=%d \n", c); c=a - b; printf("a-b=%d \n", c); c=a ***** b; printf("ab=%d \n", c); c=a / b; printf("a/b=%d \n", c); c=a % b; printf("Remainder when a divided by b=%d ", c); } Output: a+b= a-b= ab= a/b= Remainder when a divided by b=

ASSIGNMENT OPERATOR

  • The most common assignment operator is =.
  • This operator assigns the value in right side to the left side.
  • The syntax is shown below: variable=expression;
  • For ex: c=5; //5 is assigned to c b=c; //value of c is assigned to b 5=c; // Error! 5 is a constant.
  • The operators such as +=,*= are called shorthand assignment operators.
  • For ex, a=a+10: can be written as a+=10;
  • In the same way, we have: Operator Example Same as -= a-=b a=a-b = a=b a=a*b /= a/=b a=a/b %= a%=b a=a%b

RELATIONAL OPERATORS

  • Relational operators are used to find the relationship between two operands.
  • The output of relational expression is either true(1) or false(0).
  • For example a>b //If a is greater than b, then a>b returns 1 else a>b returns 0.
  • The 2 operands may be constants, variables or expressions.
  • There are 6 relational operators: Operator Meaning of Operator Example

    Greater than 5>3 returns true (1) < Less than 5<3 returns false (0) = Greater than or equal to 5>=3 returns true (1) <= Less than or equal to 5<=3 return false (0) == Equal to 5==3 returns false (0)

    != Not equal to 5!=3 returns true(1)
  • For ex: Condition Return values 2>1 1 (or true) 2>3 0 (or false) 3+2<6 1 (or true)
  • Example: Program to illustrate the use of all relational operators. #include<stdio.h> void main() { printf(โ€œ4>5 : %d \nโ€, 4 > 5); printf(โ€œ4>=5 : %d \nโ€, 4 >= 5); printf(โ€œ4<5 : %d \nโ€, 4 < 5); printf(โ€œ4<=5 : %d \nโ€, 4 <= 5); printf(โ€œ4==5 : %d \nโ€, 4 == 5); printf(โ€œ4!=5 : %d โ€, 4 != 5); } Output: 4>5 : 0 4>=5 : 0 4<5 : 1 4<=5 : 4==5 : 0 4!=5 : 1

LOGICAL OPERATORS

  • These operators are used to perform logical operations like negation, conjunction and disjunction.
  • The output of logical expression is either true(1) or false(0).
  • There are 3 logical operators: Operator Meaning Example && Logical AND If c=5 and d=2 then ((c==5) && (d>5)) returns false. || Logical OR If c=5 and d=2 then ((c==5) || (d>5)) returns true. ! Logical NOT If c=5 then !(c==5) returns false.
  • All non zero values(i.e. 1, -1, 2, -2) will be treated as true. While zero value(i.e. 0 ) will be treated as false. Truth table A B A&&B A||B !A 0 0 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1
  • Example: Program to illustrate the use of all logical operators. #include<stdio.h> void main() { clrscr ( ); printf(โ€œ7 && 0 : %d \nโ€, 7 && 0 ); printf(โ€œ7 || 0 : %d \nโ€, 7 || 0 ); printf(โ€œ !0 : %dโ€,! 0 ); }

Output: 7 && 0 : 1 7 || 0 : 1 !0 : 1

  • Example: Program to illustrate the use of both relational & Logical operators. #include<stdio.h> void main() { printf(โ€œ5>3 && 5<10 : %d \nโ€, 5 > 3 && 5 < 10); printf(โ€œ 8<5 || 5= =5 : % d \nโ€, 8 < 5 || 5 == 5); printf(โ€œ!(8 = =8) : %d โ€,! (8 == 8) ; } Output: 5>3 && 5<10 : 1 8<5 || 5= =5 : 1 !(8 = =8) : 0

TYPE CONVERSION

  • Type conversion is used to convert data of one type to data of another type.
  • Type conversion is of 2 types as shown in below figure:

IMPLICIT CONVERSION

  • If a compiler converts one type of data into another type of data automatically, it is known as implicit conversions.
  • There is no data loss in implicit conversion.
  • The conversion always takes place from lower rank to higher rank. For ex, int to float as shown in the above datatype hierarchy.
  • For ex: int a = 22, b=11; float c = a; //c becomes 21. float d=b/c=11/22.000000=11.000000/22.000000=0.
  • If one operand type is same as other operand type, no conversion takes place and type of result remains same as the operands i.e. int+int=int float+float=float
  • Conversion rules are as follows: โ†’ If either operand is long double, convert the other to long double. โ†’ Otherwise, if either operand is double, convert the other to double. โ†’ Otherwise, if either operand is float, convert the other to float. โ†’ Otherwise, convert char and short to int. โ†’ Then, if either operand is long, convert the other to long.
  • Example: Program to illustrate implicit conversion. #include<stdio.h> void main() { int a = 22, b=11; float d ; d=b/c; printf("d Value is : %f ", d ); } Output: d Value is : 0.

EXPLICIT CONVERSION

  • When the data of one type is converted explicitly to another type with the help of some pre-defined functions, it is called as explicit conversion.
  • There may be data loss in this process because the conversion is forceful.
  • The syntax is shown below: data_type1 v1; data_type2 v2= (data_type2) v1; where v1 can be expression or variable
  • For ex: float b=11.000000; int c = 22; float d=b/(float)c=11.000000/22.000000=0.
  • Example: Program to illustrate explicit conversion. #include<stdio.h> void main() { float b=11.000000; int c = 22; float d; d=b/ (float) c; printf("d Value is : %f ", d ); } Output: d Value is : 0.