Output from C - Language.
It is very important to get output from any computer language, there is a built in function in c language printf that is used to get output from c language. This function is defined in stdio.h header file.
Its syntax is as follows
printf("Formatted String",var1,var2 ...);
It is very important to understand what "Formatted String" is.
This string basically guides the printf function how to display the output on user screen, This string has three basic things
- Text
- Format Specifiers
- Escape Sequences
Text means what ever you type alphabets, numbers etc will be printed on user screen as it is, if you want to show value of any variable you have to tell the format (type) of that variable in this Format String
Here is the list of common Format Specifiers in C - Language.
Format Specifiers in C
%d for int
%f for float
%c for character
%s for string
%u for unsigned int
%ld for long int
%lf for double
%o for octal int
%x for hexadecimal int and for Addresses too
Escape Sequences in C
for special instructions inside Format String of printf and to print some of the characters which are not legally allowed to print by printf like " inverted commas, \ backslash etc we use some special code with \ inside printf this is called escape sequence
List of Escape Sequences in C Language
\'
single quote\"
double quote\?
question mark\\
backslash\a
audible bell\b
backspace\f
form feed \n
line feed\r
carriage return\t
horizontal tabSome Examples for printf function
#include<stdio.h>
void main(void)
{
printf("Hello C Language");
}
Output:
Hello C Language
#include<stdio.h>
#include<conio.h>
void main(void)
{
int x;
x=10;
printf("Value of x is:%d",x);
}
Output:
Value of x is10
#include<stdio.h>
#include<conio.h>
void main(void)
{
int x,y;
float f;
x=5;
y=6;
f=4.5;
printf("Value of x is:%d\n",x);
printf("Value of y is:%d\n",y);
printf("Value of f:%f",f);
}
Output:
Value of x is:5
Value of y is:6
Value of f is:4.50000