70 likes | 188 Views
Basic Input - Output. Output functions. printf() – is a library function that displays information on-screen. The statement can display a simple text message or a message and the value of one or more program variables gotoxy() – positions the cursor on a specific location on the screen
E N D
Output functions • printf() – is a library function that displays information on-screen. The statement can display a simple text message or a message and the value of one or more program variables • gotoxy() – positions the cursor on a specific location on the screen • clrscr() – clears the screen and place the cursor at the upper left hand portion of the screen
Input functions • scanf() – reads data from the keyboard according to a specified format and assigns the input data to one or more program variables. For numeric variables, the address can be passed by the address of operator, the ampersand (&) that is placed at the beginning of the variable name. • getch() / getche() – gets a character from the keyboard. It waits until a key is pressed and then returns the inputted character to the calling function. Unlike the scanf() function, getch/e() does not wait for the carriage return key to be pressed. The difference between the getch() and getche() is that the latter echoes the typed character to the screen.
Escape Sequences • \r carriage return • \n newline • \t move to the next tab • \a beep the speaker • \b backspace • \’ prints single quote • \” prints double quote • \\ prints backslash character • \xdd prints character whish is in hexadecimal form
Format Specifier • %c character • %s string • %d integer • %f float • %e exponential • %x hexadecimal • %o octal • %ld long integer • %lf long float / double precision
Declaration of Variables • A variable is a named data storage location in your computer’s memory. Variables in C can contain letters, digits and the underscore character ( _ ). It should be remembered that C language is case sensitive; two similar words in different cases generate two different variables. • A variable declaration tells the compiler the name and type of a variable and optionally initializes the variable to a specific value. When a variable is declared, the compiler sets aside a storage space for the variable.