Thursday 28 October 2010

I/O of integers in C

I/O of integers in C

#include<stdio.h>
int main()
{
    int c=5;
    printf("Number=%d",c);
    return 0;
}
Output
Number=5
Inside quotation of printf() there, is a conversion format string "%d" (for integer). If this conversion format string matches with remaining argument,i.e, c in this case, value of c is displayed.

#include<stdio.h>
int main()
{
    int c;
    printf("Enter a number\n");
    scanf("%d",&c);
    printf("Number=%d",c);
    return 0;
}

Output
Enter a number
4
Number=4
The scanf() function is used to take input from user. In this program, the user is asked a input and value is stored in variable c. Note the '&' sign before c. &c denotes the address of c and value is stored in that address.

No comments:

Post a Comment