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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:18:32+00:00 2026-06-12T06:18:32+00:00

Suppose I have below program, typedef struct xyz { int abc[6];//int abc; //int yz;

  • 0

Suppose I have below program,

 typedef struct xyz
    {
    int abc[6];//int abc;
    //int yz;
    }xyz;
    int main()
    {
    int *ptr = new int(10);
    int *ptr1 = new int(20);

    xyz* XYZ = reinterpret_cast <xyz*>(ptr); //Initializes XYZ->abc[0]
    XYZ = reinterpret_cast <xyz*>(ptr1);//Initializes XYZ->abc[0]

    }

Here the value enters into zeroth location. If I would like to push the value into XYZ->abc[1], then how can I do this?

  • 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-12T06:18:33+00:00Added an answer on June 12, 2026 at 6:18 am

    Maybe you want to do

     XYZ = reinterpret_cast<xyz*> (ptr1+1);
    

    But this kind of code is disgusting, it probably is an undefined behavior (because ptr1+1 might not be a valid location, and you could get a segmentation fault), so you should avoid doing that.

    I actually don’t understand the motivation (and use case) of your question.

    Maybe you wanted to allocate ten ints on the heap. Then code

    int *ptr = new int[10];
    

    and don’t forget to initialize them, e.g. with memset (ptr, 0, sizeof(int)*10);

    On Linux systems, I strongly suggest to compile with g++ -Wall -g and to use valgrind and gdb to debug your program. You really want to know these tools.

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

Sidebar

Related Questions

Suppose I have a function like below: # cat 003.c int foo(int a, int
Suppose I have a Java program Test.class , if I used the below script
Suppose I have the view models below. public class CustomerListViewModel { public IEnumerable<CustomerViewModel> Customers
Suppose I have an XSD file having below lines of code; <xsd:simpleType name=test> <xsd:restriction
I have a sequential dataset which has some data formatted in columns. suppose below
Situation Well, as you can see below, I have a main App, creating a
Suppose you have two classes, as in the example below. How would you modify
I am using Dijkstra algorithm in a program. Suppose I have a graph with
Suppose I have a scenario like below : There are about 225 Computers having
I have multiple assignment statement in my program as shown below where query.constraints.size() is

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.