0

See this answer

I understood it except for the last statement.

the conversion specifier "%d" skips optional leading whitespace and (tries to) converts the rest of the input to integer (if no errors occur).

I understood the point regarding the optional whitespace. But what does "converts the rest of the input to integer" means? I mean why will it convert the input to integer if the input itself is an integer?

1 Answers1

0

The input itself is an integer?

No, the input from key board is string(ascii), So the scanf Convert it to integer and store it in the variable.

See this:

#include <stdio.h>

int main()
{
    char cnum[] = "123";
    int  num = 0;

    int i=0;
    while(cnum[i])
    {
        num*=10;
        num+= cnum[i]-'0';
        i++;
    }

    printf("%d",num);  //This also converts int to string to print

    return 0;
}

Thanks.

srilakshmikanthanp
  • 2,231
  • 1
  • 8
  • 25