Hello, i'm new to C and i have no idea why i'm constantly getting 2293532 as the output value of %d. Any help is appreciated, thanks!

#include <stdio.h>
#include <stdlib.h>

int main(void)
    int friends;
    printf("How many friends do you have? \n");
    scanf(" %d", &friends);
    printf("You have %d friend%s", &friends, (friends!=1) ? "s" : "" );

    return 0;

Recommended Answers

All 2 Replies

Line 9: Remove the & from &friends. That'll fix it!
Using &friends causes the address of the int variable called friends to be printed via printf. Remove the & and the value stored in the friends variable will be printed!

Also, I'm not sure if the space in front of %d in the scanf() function will require that the user input a space before the number.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.