Integer may be octal or in hexadecimal : %i Example using printf and scanf function

C Programming Language / Overview of C Language

849

Program:


#include <stdio.h> 
int main() 
{ 
    int a = 0; 
    scanf("%i", &a); // input is 017 (octal of 15 ) 
    printf("%d\n", a); 
    scanf("%i", &a); // input is 0xf (hexadecimal of 15 ) 
    printf("%d\n", a); 
    return 0; 
} 

Output:

017
15
0xf
15
Press any key to continue . . .

Explanation:

scanf(char *format, arg1, arg2, …)

This function take input using standard input (keyboard) and store it in variable accordingly. It returns the number of items successfully read. Formal parameter arg1, agr2, .. must be a pointer


This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.