Download presentation
Presentation is loading. Please wait.
Published byDorcas Lambert Modified over 8 years ago
1
Data Types and Input Output in C
2
Size of a Character in C #include int main() { char ch; ch = 'A'; printf("ch = %c\n",ch); printf("size of char = %d bytes", sizeof(ch)); return 0; }
3
Size of a Character in C #include int main() { char ch; ch = 'A'; printf("ch = %c\n",ch); printf("size of char = %d bytes", sizeof(ch)); getch(); return 0; }
4
Using ASCII Values #include int main() { char ch; ch = 65; printf("ch = %c\n",ch); printf("size of char = %d bytes", sizeof(ch)); return 0; }
5
Short int #include int main() { short sh; sh = 6; printf("sh = %d\n",sh); printf("size of short = %d bytes", sizeof(sh)); return 0; }
6
int #include int main() { int i; i = 6000; printf("i = %d\n",i); printf("size of int = %d bytes", sizeof(i)); return 0; }
7
long #include int main() { long l; l = 600000; printf("l = %ld\n",l); printf("size of long = %d bytes", sizeof(l)); return 0; }
8
Float #include int main() { float flt; flt = 6.3267; printf("flt = %f\n",flt); printf("size of float = %d bytes", sizeof(flt)); return 0; }
9
double #include int main() { double dbl; dbl = 6326734.454; printf("dbl = %f\n",dbl); printf("size of double = %d bytes", sizeof(dbl)); return 0; }
10
Long double #include int main() { long double ldbl; ldbl = 63265334734.454; printf("ldbl = %Lf\n",ldbl); printf("size of long double = %d bytes", sizeof(ldbl)); return 0; }
14
i
16
Input/Output Operations and Functions
17
printf function
19
Printing expressions of variables
20
scanf function
22
,
23
A First Book of ANSI C, Fourth Edition23 Interactive Input (continued) This statement produces a prompt Address operator (&)
24
A First Book of ANSI C, Fourth Edition24 Interactive Input (continued) scanf() can be used to enter many values scanf(“%f %f",&num1,&num2); //"%f%f" is the same A space can affect what the value being entered is when scanf() is expecting a character data type – scanf(“%c%c%c",&ch1,&ch2,&ch3); stores the next three characters typed in the variables ch1, ch2, and ch3 ; if you type x y z, then x is stored in ch1, a blank is stored in ch2, and y is stored in ch3 – scanf (“%c %c %c",&ch1,&ch2,&ch3); causes scanf() to look for three characters, each character separated by one space
25
A First Book of ANSI C, Fourth Edition25 Interactive Input (continued) In printing a double-precision number using printf(), the conversion control sequence for a single-precision variable, %f, can be used When using scanf(), if a double-precision number is to be entered, you must use the %lf conversion control sequence scanf() does not test the data type of the values being entered In scanf(“%d %f", &num1, &num2), if user enters 22.87, 22 is stored in num1 and.87 in num2
26
scanf #include int main() { char ch, ch1, ch2; scanf("%c%c%c", &ch, &ch1, &ch2); printf("ch = %c\n", ch); printf("ch1 = %c\n", ch1); printf("ch2 = %c\n", ch2); return 0; }
27
scanf #include int main() { char ch, ch1, ch2; scanf("%c %c %c", &ch, &ch1, &ch2); printf("ch = %c\n", ch); printf("ch1 = %c\n", ch1); printf("ch2 = %c\n", ch2); return 0; }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.