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 9248661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:59:37+00:00 2026-06-18T09:59:37+00:00

Its generally known that things on the stack are not initialized by default. I

  • 0

Its generally known that things on the stack are not initialized by default. I tried to prove that with a struct on the stack, but unexpectedly my pointer is initialized with null, but why? What is initializing this pointer?

#include <stdio.h>
#include <string.h>

struct strustri {
    int var1;
    char *var2;
};

int main()
{
    struct strustri test1 = {
            .var1 = 12,
            .var2 = "Teststring",
    };
    struct strustri test2;

    printf("test1.var1 is %d\n", test1.var1);
    printf("test2.var1 is %d\n", test2.var1);

    printf("test1.var2 points to %p\n", test1.var2);
    printf("test2.var2 points to %p\n", test2.var2);
    return 1;
}

And this is the output on my machine (Ubuntu 12.10):

test1.var1 is 12
test2.var1 is -1271814320
test1.var2 points to 0x400634
test2.var2 points to (nil)

I ran my example multiple times. I get another value for var1 everytime, but var2 is always points to zero (null pointer)…

  • 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-18T09:59:39+00:00Added an answer on June 18, 2026 at 9:59 am

    Nothing is initializing it.

    It’s just an artefact of whatever rubbish happens to be on your stack. Switch the order of the variable declarations, or add some more local variables, and you’ll get a different result.

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

Sidebar

Related Questions

I know that messaging nil is not an error, and generally it's not an
Its generally related to a question in magento ..but i think using core php
How ASP.NET compiles its assemblies generally confuses me. It seems that I cannot program
I know that Stack Exchange sites do not use the ASP.NET MVC built-in @Html.AntiForgeryToken()
I know that exceptions have a performance penalty, and that it's generally more efficient
...meaning pattern in its general English usage, not specific to OO design patterns. Given
This is a general question of sorts, but do you think that it's important
Generally when I use ClickOnce when I build a VB.NET program but it has
Microsoft is pretty clear that .NET identifiers or parameters should not contain abbreviations. Straight
I've seen how iphone users delete from lists - its generally a swipe action

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.