0% found this document useful (0 votes)
5 views

C Prog Basics and Type Conversion

The document discusses input/output statements, arithmetic operators, and type conversions in C programming. It introduces scanf() and printf() for input and output. It describes integer, real, and mixed mode arithmetic and the results. Integer division truncates remainders while modulo returns the remainder. Implicit conversion converts integers to floats, while explicit conversion with a cast maintains the original type.

Uploaded by

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

C Prog Basics and Type Conversion

The document discusses input/output statements, arithmetic operators, and type conversions in C programming. It introduces scanf() and printf() for input and output. It describes integer, real, and mixed mode arithmetic and the results. Integer division truncates remainders while modulo returns the remainder. Implicit conversion converts integers to floats, while explicit conversion with a cast maintains the original type.

Uploaded by

bhaveshreddygun
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

First program

Standard Input output statemts(I/o)


• scanf( ) :-
• scanf() is used to read information from the standard I/P device.
• Syntax:- scanf(“controlstring”, &variable_names);
Printf(): is used to print information on the standard output device.
Syntax: printf(“control string”, var1,var2……);
Control string / format specifier
Arithmetic Operators
• Integer Arithmetic:
• If both the operands in an arithmetic expression are integers then it is known as integer
arithmetic and the result is an integer.
• Real Arithmetic:
• If both the operands in an arithmetic expression are real operands then it is known as real
arithmetic and the result is real.
• Mixed mode Arithmetic:
• If the operands in an arithmetic expression are of different types then it is known as
mixed mode arithmetic and the result is a real
Arithmetic Operators
• Integer division truncates any fractional part.

• The modulo division operation produces the remainder of an integer


division.

• Modulus operator is not valid for real and mixed mode arithmetic.
Integer Division
• #include<stdio.h> • Out put:
• int main() • 2
• {
• int res;
• res=5/2;
• printf(“%d”,res);
• }
Implicit Conversion
• #include<stdio.h> • Output:
• int main() • 2.000000
• {
• float res;
• res=5/2;
• printf(“%f”,res);
• }
Explicit conversion
• #include<stdio.h> • Output:
• int main() • 2.500000
• {
• float res;
• res=(float)5/2;
• printf(“%f”,res);
• }
Explicit Type casting
In this type of conversion, the programmer can convert one data type to other data type explicitly.
• Syntax: (datatype) (expression)
• Expression can be a constant or a variable
• Ex: y = (int) (a+b)
• double a = 6.5;double b = 6.5
• int result = (int) (a) + (int) (b)
• result = 12 instead of 13.
• int a=10
• float(a)->10.00000

You might also like