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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:42:53+00:00 2026-05-27T17:42:53+00:00

How to print a particular member of a structure using pointer arithmetic? I have

  • 0

How to print a particular member of a structure using pointer arithmetic? I have a structure with 2 members. I want to print out member j by manipulating the memory of the pointer to that structure.

#include <stdio.h>
#include <conio.h>

typedef struct ASD
{
    int i;
    int j;
}asd;

void main (void)
{
    asd test;
    asd * ptr;

    test.i = 100; 
    test.j = 200;
    ptr = &test;

    printf("%d",*(ptr +1));

    _getch();
}
  • 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-27T17:42:53+00:00Added an answer on May 27, 2026 at 5:42 pm

    The pointer type needs to be right so that the increment adds the correct size:

    printf("%d",*( ((int*)ptr) +1));
    

    Edit: As any C programmer should know, using pointer arithmetic to access struct members is useless and dangerous. Useless because the -> operation is much more concise and precise in accessing a named member, and dangerous because naive use of pointer arithmetic will result in a number of issues. However, pointer arithmetic is what the OP asked for, so pointer arithmetic is what he got.

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

Sidebar

Related Questions

i want to print how much memory is occupying by a image when that
I want to do this (no particular language): print(foo.objects.bookdb.books[12].title); or this: book = foo.objects.bookdb.book.new();
I have a particular need which I cannot seem to figure out. I've done
A client wants to save and print out a particular page I've made for
In jsp I'm using Display tag to print a table. I want to display
I have a requirement to print data exactly in a particular position in paper.
I want to point a file dialog at a particular folder in the current
The print functionality of Excel (using VBA) is extremely slow. I'm hoping someone has
Consider: print $foo, AAAAAAAA, $foo, BBBBBBBB; Let's say I want to use this code
I have a Model called Version that looks like this: from google.appengine.ext import db

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.