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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:36:43+00:00 2026-05-14T06:36:43+00:00

I am new to C and I was reading about how pointers point to

  • 0

I am new to C and I was reading about how pointers “point” to the address of another variable. So I have tried indirect invocation and direct invocation and received the same results (as any C/C++ developer could have predicted). This is what I did:

int cost;
int *cost_ptr;

int main()
{
    cost_ptr = &cost;                          //assign pointer to cost
    cost = 100;                                //intialize cost with a value
    printf("\nDirect Access: %d", cost);
    cost = 0;                                  //reset the value
    *cost_ptr = 100;
    printf("\nIndirect Access: %d", *cost_ptr);
    //some code here

    return 0;                                  //1
}

So I am wondering if indirect invocation with pointers has any advantages over direct invocation or vice-versa? Some advantages/disadvantages could include speed, amount of memory consumed performing the operation (most likely the same but I just wanted to put that out there), safeness (like dangling pointers) , good programming practice, etc.
1Funny thing, I am using the GNU C Compiler (gcc) and it still compiles without the return statement and everything is as expected. Maybe because the C++ compiler will automatically insert the return statement if you forget.

  • 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-14T06:36:44+00:00Added an answer on May 14, 2026 at 6:36 am

    Indirect and direct invocation are used in different places. In your sample the direct invocation is prefered. Some reasons to use pointers:

    • When passing a large data structure to a function one can passa pointer instead of copying the whole data structure.
    • When you want a function to be able to modify a variable in the calling function you have to pass a pointer to the original variable. If you pass it by value the called function will just modify a copy.
    • When you don’t know exactly which value you want to pass at compile time, you can set a pointer to the right value during runtime.
    • When dynamically allocating a block of memory you have to use pointers, since the storage location is not known until runtime.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to using TDD and have been reading about mocking objects
I keep reading about how great this new Canvas element for HTML5 is and
I've been reading about the new developer-only RC0 for Silverlight, and the fact that
I've been hearing/reading a lot about the new language enhancements for C# 4. I'm
I am new to web development and WCF. I am reading some basics about
I am still very new to Ruby (reading through the Pickaxe and spending most
I'm new to Windows programming and after reading the Petzold book I wonder: is
Thanks for reading. I'm a bit new to jQuery, and am trying to make
With the following file reading code: using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read,
I am fairly new to programming and while doing a lot of reading this

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.