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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:12:54+00:00 2026-06-09T03:12:54+00:00

I have these 2 structs: #define M 100 #define N 100 typedef struct xml_Element

  • 0

I have these 2 structs:

#define M 100
#define N 100

typedef struct xml_Element {
pData_Element           data;
pAttr_Element           attr_arr[M];
struct xml_Element      *parent;
struct xml_Element      *children[N];
int                     depth;
int                     num_of_children;
int                     num_of_attr;
} Xml_Element,*pXml_Element;

  typedef struct attrElem {
      char *attrName;
      char *attrValue;
   }Attr_Element,*pAttr_Element;

and I wrote this function:

pAttr_Element getXmlAttrArray(pXml_Element node) {
    return node->attr_arr;
}

I have a couple of questions:

  1. Why is it illegal? If I change the function to: {pAttr_Element* getXmlAttr....} it works but I don’t understand why.

Inside my struct I have a pointer to an array, where every cell is a pointer of type pAttr_Element right? Or it’s not a pointer to an array? I’m lost 🙁

  1. Why is it not working if I change the function to: Attr_Element getXmlAttrArray(..)?
    When I return: node->attr_arr what is the return type?

  2. How can I change the struct in order to return a pointer to an array Of pAttr_elements?

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-09T03:12:55+00:00Added an answer on June 9, 2026 at 3:12 am

    The attr_arr field is an array of pAttr_Element, not a pAttr_Element. So you can’t return it as pAttr_Element.
    In C, arrays are not pointers, but they decay to pointers in many cases. When you write return node->attr_arr, the array decays to a pointer, which is then returned.

    The xml_Element structure doesn’t contain a pointer to the array of pAttr_Element. It actually contains 100 such structures.

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

Sidebar

Related Questions

I have these structs: typedef struct _Frag{ struct _Frag *next; char *seq; int x1;
I have these two files: test.h #ifndef TEST_H #define TEST_H typedef struct _vertex_node {
I have a structure defined like so: typedef struct { int n; int *n_p;
I have a struct defined as follows: template <typename T> struct data { int
I have the following struct in C++: #define MAXCHARS 15 typedef struct { char
I have a metafunction: struct METAFUNCION { template<class T> struct apply { typedef T
I have a BST library in wich I store some structs : struct bst_node
I have following Structure in my Program. #define WIFI_DEVICE_NAME 100 #define WIFI_SERIAL_NO 13 #define
Assume I have the struct Foo struct Foo{ int a; short b; char c;
I have two structs containing some fields: struct MyNodeData, and struct MyEdgeData. When I

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.