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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:56:36+00:00 2026-05-26T03:56:36+00:00

I tried the following program struct temp{ int ab; int cd; }; int main(int

  • 0

I tried the following program

struct temp{
   int ab;
   int cd;
};

int main(int argc, char **argv)
{
   struct temp *ptr1;
   printf("Sizeof(struct temp)= %d\n", sizeof(struct temp));
   printf("Sizeof(*ptr1)= %d\n", sizeof(*ptr1));
   return 0;
}

Output

Sizeof(struct temp)= 8
Sizeof(*ptr1)= 8

In Linux I have observed at many places the usage of sizeof(*pointer). If both are same why is sizeof(*pointer) used ??

  • 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-26T03:56:37+00:00Added an answer on May 26, 2026 at 3:56 am

    I generally prefer sizeof(*ptr) because if you later go back and change your code such that ptr now has a different type, you don’t have to update the sizeof. In practice, you could change the type of ptr without realizing that a few lines further down, you’re taking the structure’s size. If you’re not specifying the type redundantly, there’s less chance you’ll screw it up if you need to change it later.

    In this sense it’s one of those “code for maintainability” or “code defensively” kind of things.

    Others may have their subjective reasons. It’s often fewer characters to type. 🙂

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

Sidebar

Related Questions

I tried to compile following program with gcc. 0 #include <stdio.h> 1 2 main
I have tried the following program for writing the contents into Spreadsheet. I downloaded
I tried the following program on Visual Studio 2010. #include <iostream> using namespace std;
I'm trying to break into SSE2 and tried the following example program : #include
I tried to execute the following actionscript3 program and I am surprised of the
I tried three iterations of the following simple program. This is a highly simplified
I just started with learning vala. I tried the following program from the vala
Consider the following program: #include <iostream> #include <algorithm> using namespace std; template<class T> struct
Tried following the instructions here: How to use Google app engine with my own
I tried following the answer to this question , but could not get xsd.exe

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.