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

  • Home
  • SEARCH
  • 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 8144827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:29:05+00:00 2026-06-06T13:29:05+00:00

Does printf occupy memory in the stack? printf(Hello world); Does Hello world have a

  • 0

Does printf occupy memory in the stack?

printf("Hello world");

Does "Hello world" have a constant address?

Please help me understand.

EDIT:

Is the argument we are passing for the printf is stored in a local pointer variable.
If I use an array to store a 50 string literals it takes stack memory but if Ii use the printf it doesn’t take memory – is what i heard. But I don’t know how printf doesn’t take memory as the array we declared.

Please help me understand!

  • 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-06-06T13:29:08+00:00Added an answer on June 6, 2026 at 1:29 pm

    It depends on your platform’s calling convention and how the standard library is implemented.

    For example, take the following program:

    #include <stdio.h>
    
    int main(void)
    {
      printf("Hello, World\n");
      return 0;
    }
    

    and the following command line to compile it:

    gcc -S -std=c99 -pedantic -Wall -Werror syscall.c
    

    On a 32-bit Red Hat box (i686) using gcc 2.96, we get the following machine code:

          1         .file   "syscall.c"
          2         .version        "01.01"
          3 gcc2_compiled.:
          4                 .section        .rodata
          5 .LC0:
          6         .string "Hello, World\n"
          7 .text
          8         .align 4
          9 .globl main
         10         .type    main,@function
         11 main:
         12         pushl   %ebp
         13         movl    %esp, %ebp
         14         subl    $8, %esp
         15         subl    $12, %esp
         16         pushl   $.LC0
         17         call    printf
         18         addl    $16, %esp
         19         movl    $0, %eax
         20         leave
         21         ret
         22 .Lfe1:
         23         .size    main,.Lfe1-main
         24         .ident  "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2)"
    

    Line 16 pushes the address of the string literal onto the stack, and then printf is called.

    Here’s the same code, compiled the same way, on a 64-bit SLES 10 box (x86_64) using gcc 4.1.2:

    
          1         .file   "syscall.c"
          2         .section        .rodata
          3 .LC0:
          4         .string "Hello, World"
          5         .text
          6 .globl main
          7         .type   main, @function
          8 main:
          9 .LFB2:
         10         pushq   %rbp
         11 .LCFI0:
         12         movq    %rsp, %rbp
         13 .LCFI1:
         14         movl    $.LC0, %edi
         15         call    puts
         16         movl    $0, %eax
         17         leave
         18         ret
    ;;
    ;; additional content not included
    ;;
    

    In this case, line 14 writes the address of the string literal to a register (%edi) instead of pushing it onto the stack. Note also that this version of gcc is smart enough to realize that since I’m passing a single argument of type char *, it can substitute a call to puts.

    In either case you’re creating a new stack frame when you make the call; the difference is what’s in the stack frame. On the Red Hat box, it will include the address of the string literal; on the SLES 10 box, it won’t.

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

Sidebar

Related Questions

main() { printf(Hello World.); } Why does no warning is produced in gcc compiler
Possible Duplicate: Why does Mac's $find not have the option -printf? Not sure what
printf(%d,printf(%*s%*s,6,,6)) Results in the addition of the 2 numbers (6+6), does anyone have on
c='q'; while(c=='q') { printf(hello); scanf(%c,&c); } Why does the loop exit without any reason
How does Variable Length Argument lists functions like printf() , scanf(), etc in C
If a=3 and b=5 what does this imply? printf(&a[Ya!Hello! how is this? %s\n], &b[junk/super]);
In my programming class, I don't understand what the value of printf(World) is (question
I have a multi-threaded program and cannot figure out why the printf does not
The following code does not compile: let x = hello in Printf.printf x The
Why does C's printf format string have both %c and %s ? I know

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.