Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

something is wrong when using pointers

When I put in the code for pointers I get back "N is always the same as N". If c is pointing to k then why is it giving me N?

{
    char *letter;

    char c = "k";

    letter = &c;
    printf("%c is always the same as %c\n", c, *letter);
    return 0;
}

main.c:16:10: Incompatible pointer to integer conversion initializing 'char' with an expression of type 'char [2]'

1 Answer

Hey Andrew,

The problem that I see is that you're assigning a string to a char variable. Try this instead:

char *letter;
char c = 'k';    // use single quotes

letter = &c;
printf("%c is always the same as %c\n", c, *letter);
return 0;