simple question

This is a discussion on simple question within the C Programming forums, part of the General Programming Boards category; I have a simple question. I dont understand why this is not printing an 'a' to the screen i think ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    5

    simple question

    I have a simple question. I dont understand why this is not printing an 'a' to the screen i think it is giving me a K .

    Code:
    #include <stdio.h>
    
    int main (void)
    {
     char a;
     a= 'a';
     printf ("%c", &a);
     return 0;
    }

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > a= 'a';
    Don't you need the regular "double" quotes such as the ones that surround the word double in this sentance?

    > printf ("%c", &a);
    This shouldn't have the & sign.
    The world is waiting. I must leave you now.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Try this: Remove the & before the a in printf(). Putting the & in front of the name of the variable, gives the address of that variable, not the value.

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    5
    if i use double quotes it gives me this error

    warning: assignment makes integer from pointer without a cast

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >Don't you need the regular "double" quotes such as the ones
    >that surround the word double in this sentance?

    That is for strings, he is using a single character.

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    5
    ty guys the use of single quotes and removing the & worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 08:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 11:15 AM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 05:58 PM

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