|
INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
C
DETAILS
Question: Why does a linker error occurs for the segment: main() { extern int i; i=20; printf("%d",sizeof(i)); }
Answer: You cannot define the value of an extern variable, should be defined in some other header or cpp file, so it will give a linker error.
|
|
|
Category |
C Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 9648 users |
Added on |
5/19/2013 |
Views |
68997 |
Rate it! |
|
|
Question:
Why does a linker error occurs for the segment: main() { extern int i; i=20; printf("%d",sizeof(i)); }
Answer:
You cannot define the value of an extern variable, should be defined in some other header or cpp file, so it will give a linker error. Source: CoolInterview.com
Answered by: Himanshu Sharma | Date: 5/20/2008
| Contact Himanshu Sharma
Here variable 'i' has decalred as extern. Then, compiler won't allow any memory to this variable and later, we are trying to access a variable for which memory was not allocated at all. Hence, it gives linker error. Source: CoolInterview.com
Answered by: Kishore | Date: 6/16/2008
| Contact Kishore
The extern specifies only declaration ie it indicates to the compiler that "i" will be used(in the scope of its declaration) but its memory is allocated in some other file. Now since memory is not allocated to i,its size is unknown and we cannot use it.The error is detected by linker since linker does the task of external references. Source: CoolInterview.com
Answered by: Manik Sidana | Date: 8/19/2008
| Contact Manik Sidana
ans is 2, because the purpose of sizeof() is sizeof operator to calculate the number of elements in the array. Source: CoolInterview.com
Answered by: sampath reddy | Date: 9/5/2010
| Contact sampath reddy
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Can there be a mouse click and drag function used together to rotate a circle in c?please give which are they?
|
View Answer
|
|
Can there be a mouse click and drag function used in c?
|
View Answer
|
|
Between n+1 and n++ which executes faster or both take the same time to execute?
|
View Answer
|
|
Range of int in is -32768 to 32767 and it occupy 2 byte in memory and char take 1 byte take single char but in java int is 4 byte take value-2,147,483648 to 647 and char occupy 2 byte and also take single variable why not more?`
|
View Answer
|
|
How to connect a database (MS Access) to Borland C? Please give me step by step coding.
|
View Answer
|
|
To which numbering system can the binary number 1101100100111100 be easily converted to?
|
View Answer
|
|
What are bit fields? What is the use of bit fields in a structure declaration?
|
View Answer
|
|
What are enumerations?
|
View Answer
|
|
Write down the equivalent pointer expression for reffering the same element a[i][j][k][l]?
|
View Answer
|
|
What is the use of typedef?
|
View Answer
|
|
Which mistakes are called as token error?
|
View Answer
|
|
What is the function of % using in formatted string.
|
View Answer
|
|
How to print the names of employees or students in alphabetical order using C programming?
|
View Answer
|
|
How should i rate on the basis of the basis of the scenario the insertion sort , bubble sort , Quick Sort?
|
View Answer
|
|
Can we print values from 1 to 100 without using for,while,do-while,if etc.?answer should be logical.
|
View Answer
|
|
How to write a program to print its own source code?
|
View Answer
|
|
What are the advantages of pointers,give me programs containing variables and pointer variables?
|
View Answer
|
|
I want source code of series of prime numbers.
|
View Answer
|
|
There is any methodology in which we can print a string in c without using semicolon(;) suggest me if there is ?
|
View Answer
|
|
What is the difference between the following statements? int a[4]={1,2,3,4}; int a[]={1,2,3,4);
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All C Interview Questions & Answers - Exam Mode /
Learning Mode
|