Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6364825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:12:51+00:00 2026-05-25T00:12:51+00:00

char buffer[10]; strcat(buffer, hi); printf(%s, buffer); In the above code, it prints some weird

  • 0
char buffer[10];
strcat(buffer, "hi");
printf("%s", buffer);

In the above code, it prints some weird symbol or number followed by the “hi”, I know strcat is appending to buffer. And I normally zero the memory in buffer. But i’m curious why I usually have to do that.

If i do printf("%i", buffer); without the strcat, it just prints a random number. What is that number? Could anyone explain or link to a tut that explains what is in buffer, before I fill it with anything?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:12:52+00:00Added an answer on May 25, 2026 at 12:12 am

    “buffer” is a 10 byte region on the stack, and it’d contain whatever was last written to that region of memory. When you strcat, it would concatenate “hi” after the first null byte in that region (So if the first null byte is beyond 10 bytes, you’d overwrite something on the stack). When you print without zeroing, it’d print the bytes until the first 0 (null). Again, this might print beyond the 10 bytes.

    When you printf (%I, buffer), you print the address of that location.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the following code: char buffer[2047]; int charsRead; do { if(fscanf(file, %2047[^\n]%n%*c, buffer,
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
Hey guys, here is my code. int main() { char buffer[BUFSIZE]; // define our
I know that buffer overruns are one potential hazard to using C-style strings (char
I'm porting my application into Linux (from Windows). I have such code: char buffer[32]
I have a couple of questions related to the following code: char buffer[256]; memset(buffer,0,256);
This code displays hello in chinese char buffer[10]=hello; AfxMessageBox((LPCTSTR)buffer); while this code displays it
I have this block of code: int myFunc( std::string &value ) { char buffer[fileSize];
I have a char* buffer and I am interested in looking at the first
i have a char buffer[100] and i'm trying to use gdb to read the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.