top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

typedef variable is it applicable to first variable or all in the row?

+3 votes
396 views

typedef int *ptr;
ptr p1, p2;

In this P2 is Integer Pointer or Integer?

posted Jan 21, 2014 by Prachi Agarwal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

+1 vote
#include <stdio.h>

typedef int *ptr; 

int main()
{
   ptr p1, p2;

   *p1 = 5;
   *p2 = 5; 
   printf("%d\n", *p1);
   printf("%d\n", *p2);
   return 0;
}

Output

5
5

Which proves that both p1 and p2 are of type (int *) i.e. integer pointer...

answer Jan 22, 2014 by Sheetal Chauhan
+1 vote

typedef will be effected on both variable p1 as well on p2.
In case of both will be pointer p1 as well as p2

#define int *ptr

then
ptr p1, p2; will be int *p1,p2;
here only p1 will be pointer only.

answer Jan 22, 2014 by Vikas Upadhyay
0 votes

No P2 is an Interger Pointer not Integer.

For eg:
int *p1,p2;
Then p1 will be the integer Pointer but p2 is an Integer.

answer Jan 22, 2014 by Pankaj Kumar
Similar Questions
0 votes
#define MY_STRUCT
typedef struct{ 
...
... 
} my_struct;

Above code is giving me error (MY_STRUCT) is not working as expected, Looks that some silly mistake, please point out as I have wasted many hours?

Sorry for hiding my identity?

+1 vote

In large product based companies LLD is written by senior team members and developers write the code.
Does the senior team member decide what data type they should use in advance ? If yes then what things derives type of data for example. How they decide a variable should be declared as volatile ? and what would be advantage of having a variable volatile and what could be the problem if it is taken without the volatile ?

+2 votes

How can I wwap value two variables without using third variable or +/- operator?

+5 votes

In a large project . There is a lots of header files included one another and I do not know the header file in which MYINT is define.

How will I know that MYINT is

#define MYINT int

OR

typedef int MYINT
...