Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8153757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:07:29+00:00 2026-06-06T16:07:29+00:00

int x; scanf(%d,&x); printf(%d,x); Input: . (just a period) Output: 4096 Why does it

  • 0
int x;
scanf("%d",&x);
printf("%d",x);

Input: . (just a period)
Output: 4096

Why does it output 4096 here. Here is what I am thinking: So the ASCII value of a period is 46. Upon input, it reads in x as the bit pattern for 46? And when it prints, does it print out four bytes at the memory location of x, so only the first byte is filled with the bit pattern corresponding to 46, and the rest is random stuff that makes up the 4096? But this is incorrect, because look what happens when I do this–

int x;
scanf("%d",&x);
printf("%c",x);

Input: . (period)
Output: (nothing)

Input: 46
Output: . (period)

Even more confusing is what is going on when I do this:

int x;
scanf("%c",&x);
printf("%d",x);

Input: . (period)
Output: 4142

Input: 46
Output: 4148

Input: 47
Output: 4148
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:07:32+00:00Added an answer on June 6, 2026 at 4:07 pm

    You need to check the return value of scanf (it’s the count of successfully read values):

    int x;
    
    if (scanf("%d",&x) == 1) {
        printf("%d", x);
    } else {
        printf("Invalid input.");
    }
    

    If the parsing failed, the value of x is not defined.

    Once scanf has failed, further calls will also fail because the invalid input is not removed from the stream. Because of this it is not a good idea to use scanf.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code int arr[5]; printf(Input values:); for (i=0;i<5;i++) scanf(%d,&arr[i]); pthread_create(&thread1, NULL,
I came across the following code : int i; for(; scanf(%s, &i);) printf(hello); As
#include<stdio.h> void function(int); int main() { int x; printf(Enter x:); scanf(%d, &x); function(x); return
//get choice input int n; scanf (%d,&n); // print the option that the user
int main(void) { char *input; printf(prompt>); scanf(%s, input); printf(%s, input); return 0; } prompt>input
int main() { int p; scanf(%d,&p); fun() { int arr[p]; // isn't this similar
#include<stdio.h> #include<time.h> int main() { clock_t start; double d; long int n,i,j; scanf(%ld,&n); n=100000;
Is it correct to use scanf() as follows: int n; scanf([%d], &n); If so,
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
I have a simple problem; Here is the code : #include<stdio.h> main(){ int input;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.