Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed C Programming - Unusual Result

+9 votes
asked Nov 10, 2025 by anonymous
closed Dec 21, 2025 by Admin
I am trying to follow the Codecademy C programming video with this code

# include <stdio.h>
# include <stdlib.h>
int main()
{
    char characterName[10] = "George";
    int age = 35;
    
    printf("There once was a man named %s\n", &characterName);
    printf("he was %d years old\n", &age);
    return 0;
}

But my output is giving me what looks like a random number in onlinegdb. My variable is initalized so shouldn't it work
closed with the note: answered

5 Answers

+5 votes
answered Nov 19, 2025 by Zach (380 points)
You're printing the address of characterName and age, not the contents. Remove '&' from '&characterName' and '&age' and it should work.
+4 votes
answered Nov 20, 2025 by Peter Minarik (101,340 points)

Your code correctly is

printf("There once was a man named %s\n", characterName);
printf("he was %d years old\n", age);

Your issue was that you did not provide the value to be printed, but the memory address of the value to be printed (see the & operator).

When you compile and run your code, the compiler even gives a warning about this.

+2 votes
answered Dec 6, 2025 by hanusai (180 points)

it should be like

# include <stdio.h>
# include <stdlib.h>
int main()
{
    char characterName[10] = "George";
    int age = 35;
    
    printf("There once was a man named %s\n", characterName);
    printf("he was %d years old\n", age);
    return 0;
}

because while writing printf statement you should not use"&" 

0 votes
answered Dec 12, 2025 by Rameshwar Kumbhar (140 points)
Your code should be as below

# include <stdio.h>
# include <stdlib.h>
int main()
{
    char characterName[10] = "George";
    int age = 35;
    
    printf("There once was a man named %s\n", characterName);
    printf("he was %d years old\n", age);
    return 0;
}
0 votes
answered Dec 16, 2025 by sai tharun (150 points)
In the above code, the printf statement ends with '&' which is not correct, try to rerun after removing those.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...