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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:30:11+00:00 2026-06-03T17:30:11+00:00

In the below example of pointer to structure #include<stdio.h> #include<stdlib.h> struct siva { int

  • 0

In the below example of pointer to structure

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

   struct siva {
   int a;
   };

   typedef struct siva *s1;

    void main()
   {
    s1 b=(s1)malloc(sizeof(s1*));
    b->a=8;
    printf("\n The vlue is s1->a is %d",b->a);
    free(b);
  }

In the above code the variable b is not declared, but how this code works

In this line

   s1 b=(s1)malloc(sizeof(s1*));

How the memory is allocated for b and why s1* is used in sizeof().
what is the difference between s1 and s1

  • 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-03T17:30:12+00:00Added an answer on June 3, 2026 at 5:30 pm

    The following is a declaration of s1‘s type as a pointer to struct siva

    typedef struct siva *s1;
    

    The following is a pointer to s1 (e.g. pointer to pointer to struct siva)

    s1*
    

    The size given in malloc is wrong, it should be

    s1 b=(s1)malloc(sizeof(struct siva));
    

    As s1 points to struct siva. It works only because the address of the first element in the struct is the address of the struct, but this is basically a dangerous thing to do.

    b is declared, in the same line it is assigned to:

        s1 b=(s1)malloc(sizeof(s1*));
    //  ^^^^
    

    Note that in C you are not allowed to initialize a variable from a function’s return value.

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

Sidebar

Related Questions

Let's consider the below example. There, I have: target MAIN calls target t and
The example below uses a function pointer to a member function of the class
Below is a simple example of using pointer in delphi. Type TRecord1 = Record
I'm viewing the below example in Chrome and can't seem to get cursor: pointer
Context: C++ Consider the example below class TestClass { private: int A[]; int *B;
virtual function resolution happens with pointer/reference and not with object. Now consider below example:
I have this structure: typedef struct { char *str; ... } nameType; I create
How can I get only unique departments from the below example? Dept Id Created
The example below, is just an example, I know that I don't need an
this example below works when hover event is trigered and when its not, its

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.