Thread: Clearing thought on pointer usage ?

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    3

    Clearing thought on pointer usage ?

    Hi,
    to everybody

    I am using C language since few months. I have learnt C at my bachelor Engg. But since then I have not been using it.

    I have some doubt on pointer usage.

    Can anyone tell me when to pass address as an arguments to function and when to pass pointer as an argument to the function?

    If you can explain with example it will be great...or any link to this particular doubt will be very helpful.

    Thanks in advance.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Can anyone tell me when to pass address as an arguments to function and when to pass pointer as an argument to the function?
    Well, an address is a pointer's value. A pointer is supposed to hold the memory address of an object of a certain type, and this type is expressed when you declare a pointer, i.e.
    Code:
    int *p;
    int **q;
    Like this, *p is an int, and *q is an int*.

    So now that we know the type of pointer, say you have a function that expects an int * in the argument list. You have two things you can pass in. If you have an int, you can pass it's address (&foo). If you have a pointer, you can just write the variable name (p).

    Does this help.

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Uninitialized pointer usage: one OK, other NOK?
    By courteous in forum C Programming
    Replies: 7
    Last Post: 04-20-2010, 05:17 AM
  2. Replies: 3
    Last Post: 10-30-2009, 04:41 PM
  3. Pointer usage problem.
    By Swerve in forum C++ Programming
    Replies: 11
    Last Post: 10-17-2009, 06:11 PM
  4. I thought I understood but....(pointer question)
    By caroundw5h in forum C Programming
    Replies: 1
    Last Post: 02-22-2005, 03:05 AM
  5. Bad Pointer Usage
    By agro in forum C# Programming
    Replies: 0
    Last Post: 03-06-2004, 01:43 AM

Tags for this Thread