I knew this meaning (int *p).But I want this meaning (int *)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sathi468
    New Member
    • Jan 2014
    • 1

    I knew this meaning (int *p).But I want this meaning (int *)

    (int *p)means pointer variable of p in integer datatype
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Can you give us an example? One case where (int *) may appear would be something like this:
    Code:
    void * pointer = ...;
    int * p = (int *) pointer;
    Here you are casting the void pointer pointer to an int pointer.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      If you mean a function declaration

      Code:
      void func1(int *p); // 1
      void func2(int *);  // 2
      Then they both mean exactly the same thing, declare a function that takes 1 int pointer parameter. In a function declarations the parameter names (p in this case) are ignored.

      If you mean a function definition

      Code:
      void func1(int *p) // 3
      {
        // some code here
        *p = 5;
      }
      
      void func2(int *)  // 4
      {
        // some code here
      }
      Then the both still mean the same thing, a function that takes 1 parameter with type pointer to int, however in case 4 you are also declaring that although the function takes a pointer to int parameter it is not used by the functions implementation. A construct sometimes used when you have to create a callback function to a third party API and have no use for the passed data.

      Comment

      Working...