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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:08:27+00:00 2026-05-23T14:08:27+00:00

I did not expect to be able to increment a pointer to a struct

  • 0

I did not expect to be able to increment a pointer to a struct in a memory block of structs. But it seems to work. Is there any case where this does not work? If I create a “list” of structs then I should always be able to increment the pointer to them and C will figure out how many bytes to move by?

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

struct User {
    int id;
    char name[32];
    float net_worth;
};
typedef struct User User;


int main(int argc, char** argv) {
    User* u1 = (User*)malloc(sizeof(User));
    u1->id = 1;
    strcpy(u1->name, "Mike");
    u1->net_worth = 43.45;
    User* u2 = (User*)malloc(sizeof(User));
    u2->id = 2;
    strcpy(u2->name, "Pablo");
    u2->net_worth = -2.00;
    User* u3 = (User*)malloc(sizeof(User));
    u3->id = 3;
    strcpy(u3->name, "Frederick");
    u3->net_worth = 7329213.45;

    User** users = (User**)malloc(sizeof(User)*10);
    *users = u1;
    printf("%s\n", ((User*)(*users))->name);
    *users++;
    *users = u2;
    printf("%s\n", ((User*)(*users))->name);
    *users++;
    *users = u3;
    printf("%s\n", ((User*)(*users))->name);


    return 0;

}
  • 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-23T14:08:28+00:00Added an answer on May 23, 2026 at 2:08 pm

    This is very much by design. Assume you have

    User userArray[16];
    

    You could either access the second user via userArray[1], or *(userArray + 1), or get a pointer to the first element and increment it via ++.

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

Sidebar

Related Questions

Lot of googling did not help me! Are there any good dictionary web based
Are there any gotchas in JDK 6 which did not exist in earlier versions?
I am not a Groovy expert, but I did read the book Groovy in
I did not find any suitable questions answered yet, so I'd like to know
I did not make any changes on the code. I dont receive any errors
I create a new Button object but did not specify the command option upon
I'm experiencing some behavior I did not expect. I have a synchronous procedure that
I observed something last week that I did not expect, and will describe below.
I've encountered a behavior I did not expect when executing the following Python script
I ran in an overloading resolution problem which I did not expect. Apparently 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.