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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:39:47+00:00 2026-06-03T00:39:47+00:00

OK, this is the definition of the struct: typedef struct { int first; int

  • 0

OK, this is the definition of the struct:

typedef struct {
   int first;
   int last;
   int count;
   char * Array [50];
} queue;

and I use another function to initialize it

void initialize(queue * ptr){
   ptr=malloc(sizeof(queue));
   ptr->first=0;
   ptr->last=0;
   ptr->count=0;
}

Then I use printf to print out first, last and count. All three should be zero. However, what I actually get is, count is 0 as I expected, but first&last are two very large strange numbers and they change every time I run the program. Can anybody tell me what’s wrong here? Thank you.

  • 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-03T00:39:48+00:00Added an answer on June 3, 2026 at 12:39 am

    You are passing your pointer by value. The function changes a copy of the argument it receives, but the caller’s pointer is not modified and is probably unintialized.

    You need to change your function to take a queue** and pass the address of the pointer you want to initialize.

    Alternatively you could return a pointer instead of passing it in as an argument. This is a simpler approach.

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

Sidebar

Related Questions

Basically, I've defined and typedef'ed this struct: typedef struct{ void** elements; int numElements; int
Consider this piece of code: struct Trade { float Price; char* time; int shares;
I am using structs in my project in this way: typedef struct { int
So, I've got this definition: typedef enum { red = 1, blue = 2,
Let's use this class definition as an example: class Person def fname @fname end
Consider this #define : #define msd_buffer ((volatile char *) MSD_BUFFER_ADDRESS) and this variable definition:
I want functionality similar to the below: typedef int A; typedef int B; struct
I have the next definition in a file: File: one.h typedef struct example example;
Possible Duplicate: What does 'unsigned temp:3' means I don't understand this struct definition. It
I have these two structures... typedef struct{ MY_SECOND_STRUCT s1; }MY_FIRST_STRUCT; typedef struct{ int s1;

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.