Weird output of scanf and printf.

This is a discussion on Weird output of scanf and printf. within the C Programming forums, part of the General Programming Boards category; I've come up with the following program: Code: #include <stdio.h> int main() { int a; printf( "Enter a number: " ...

  1. #1
    Novice.
    Join Date
    Oct 2005
    Posts
    88

    Weird output of scanf and printf.

    I've come up with the following program:
    Code:
    #include <stdio.h>
    int main()
    {
     int a;
     printf( "Enter a number: " );
     scanf( "%d", &a );
     printf( "You entered %d \n", a );
     getchar();
     printf( "You entered %d", &a );
     getchar();
    }
    The program runs and puts this out:
    Code:
    Enter a number: 1
    You entered: 1
    You entered: 37814108
    It doesn't mattter which number I put in, the 37814108 will still be the output.
    I'm using Bloodshed Dev 4. Is this a strange output, or is it normal?

    Thank You.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,612
    Code:
    printf( "You entered %d", &a );
    You're printing the address of the variable a.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Novice.
    Join Date
    Oct 2005
    Posts
    88
    Well okay, that certainly explains it.

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 09:25 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  3. Newb Help: Full Arrays and Functions
    By LycanGalen in forum C Programming
    Replies: 5
    Last Post: 01-31-2008, 07:35 PM
  4. Please help debug
    By Wexy in forum C Programming
    Replies: 2
    Last Post: 11-10-2002, 11:40 PM
  5. help with switch statements
    By Wexy in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 04:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21