Welcome Guest   Login   Apr 16, 2024
Tutorials
C
HTML
Java
Chapter 2
Datatypes, Input/Output Function

 

Datatypes
 
Datatype Size (in bytes) Range Data 
int -2^15 to 2^15-1 Any non fractional value
char 1 -2^7 to 2^7-1 Any single ASCII character
float 4 No specific range Any Fractional value
long 4 -2^31 to 2^31-1 A number which is larger than int
double 8 -2^63 to 2^63 -1 Largest capacity datatype with fraction values also.

 


Format Specifiers


Format Specifier Used For getting appropriate output
%d Integer Decimal ( non fractional number )
%c Character 
%f Float
%l Long 
%s String 
%lf For presenting double data

 


Input / Output Functions

Unformatted functions
 
getch()  Waits for user to press any key, returns the key pressed that can be assigned to variable
getche()  like getch() but echoes character pressed to screen
getchar() Accepts one character from user, terminates only when user presses enter. Even if user typed more than one character return first one character only.
putchar()  can pass character type parameter, a single character that you want to appear on screen.
gets()  By passing character array as parameter can. accept string input including spaces.
puts()  By passing character array as parameter can display the content of string

 

Formatted functions

printf(char *,var,var... )

prints the formatted output on screen as specified in format specifier. same function can be used for displaying all the datatype variables.

eg. printf("i=%d, f=%f",i,f);
 
 

scanf(char *,var,var...)

Accepts the formatted input from user as specified in format specifier & in variable address given as parameter.

eg. scanf("%d",&i);


Example on all thses topics.
 
main() 
{
int x=20;
char ch='A';
float f = 3.14;
double d = 3400.233;
printf("\nx = %d", x);
printf("\nx = %c", ch);
printf("\nx = %f", f);
printf("\nx = %lf", d);
printf("\nPress any key to continue");
getch();

}

My New Blog

My Award winning Whitepaper

Contradicting Light
My Personal Blog


Trace Mobile Location



My Book Reviews
 




Tech Jokes Worth Reading
 
Top
Home
www.deepjava.com 1999-2017 (C) Developed and maintained by D-Kay Consultancy