Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

What is the difference between %i and %d in scanf() with C

1 Answer

0 votes
#include <stdio.h> 
  
int main() 
{ 
    int a, b, c;
    
    scanf("%i %i %i", &a, &b, &c);
    printf("a = %i b = %i c = %i\n", a, b, c); // take (base 10), hex (base 16) and octal (base 8)

    a = b = c = -1;
    
    scanf("%d %d %d", &a, &b, &c);
    printf("a = %d b = %d c = %d\n", a, b, c); // take only base 10 
    
    return 0; 
}



// 15 (base 10) = 15 (base 10)
// 0x15 (base 16) = 21 (base 10)
// 015 (base 8) = 13 (base 10)



/*
run:

15 0x15 015
a = 15 b = 21 c = 13
15 0x15 015
a = 15 b = 0 c = -1

*/

 



answered Apr 1, 2024 by avibootz
edited Apr 1, 2024 by avibootz

Related questions

1 answer 87 views
1 answer 95 views
1 answer 108 views
1 answer 97 views
1 answer 257 views
...