C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Point Out Correct Statements (Q.No. 6)
6.
1 : | typedef long a; extern int a c; |
2 : | typedef long a; extern a int c; |
3 : | typedef long a; extern a c; |
Answer: Option
Explanation:
typedef long a;
extern int a c; while compiling this statement becomes extern int long c;. This will result in to "Declaration syntax error".
typedef long a;
extern a int c; while compiling this statement becomes extern long int c;. This will result in to "Too many types in declaration error".
typedef long a;
extern a c; while compiling this statement becomes extern long c;. This is a valid c declaration statement. It says variable c is long data type and defined in some other file or module.
So, Option C is the correct answer.
Discussion:
14 comments Page 1 of 2.
Venkat said:
7 years ago
Above all are does not give any declaration error. so I think option D correct.
#include<stdio.h>
int main()
{
extern long c;
extern int long d;
extern long int t;
printf("%d %d %d\n",c,d,t);
return 0;
}
long int t=9;
int long d=8;
long c;
output(in gcc):user@user:~/c$ ./a.out
0 8 9
#include<stdio.h>
int main()
{
extern long c;
extern int long d;
extern long int t;
printf("%d %d %d\n",c,d,t);
return 0;
}
long int t=9;
int long d=8;
long c;
output(in gcc):user@user:~/c$ ./a.out
0 8 9
Ramy said:
1 decade ago
"long i;" is equivalent to "int long i" ; or "long int i;"
So: typedef long a;
extern int a c;
Is equivalent to extern int int long c; i.e. the problem comes from int int --> two data types in declaration specifiers.
So: typedef long a;
extern int a c;
Is equivalent to extern int int long c; i.e. the problem comes from int int --> two data types in declaration specifiers.
Suraj said:
1 decade ago
Please somebody explain why does it works fine in option no 2 when a is replaced by long manually it works fine what is its problem with 'a'? which would ultimately be replaced by the compiler before running?
JATIN said:
1 decade ago
1. typedef long a;
2. extern a int c;
In this case if we replace a in second statement with long it will not show error. And I think if we use typedef then it is literally substituted for the given name.
2. extern a int c;
In this case if we replace a in second statement with long it will not show error. And I think if we use typedef then it is literally substituted for the given name.
Kiran said:
1 decade ago
Before and after type def it will not allow any data types.
but these are valid and also same lets try
1.extern int long x
2.extern long int x
3.long extern int x
4.int extern long x
but these are valid and also same lets try
1.extern int long x
2.extern long int x
3.long extern int x
4.int extern long x
(1)
Jeychandar said:
5 years ago
@All
long is variable and int is also a variable so two variables cannot be assigned that's why 3 is correct.
long is variable and int is also a variable so two variables cannot be assigned that's why 3 is correct.
Cheri said:
1 decade ago
It is declaration not definition. Coming to second and first option we have used two data types int, long.
Chaitali said:
1 decade ago
Why extern long int c;
Is not allowed?
I have compiled the second option.
Is not allowed?
I have compiled the second option.
Shibi said:
1 decade ago
Yeah jatin is correct it will be considered as a long int datatype.
Husain said:
5 years ago
Can anyone explain how to use these in a program practically?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers