Interview Question






Comment hidden because of low score. Click to expand.
0
of 0 vote

static int i and int i are visible in the same Translation unit . Hence conflicting declarations .

- Anonymous February 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

No. the question doesn't meantion header files.

- - February 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Actualli i have tried the following codes in the C compiler.

#include<stdio.h>
int i;
static int i;
extern int i;
int main()
{
return 0;
}

It is not giving any compilation errors.

#include<stdio.h>
int i=10;
static int i=10;
extern int i;
int main()
{
return 0;
}
This code is throwing the error.(Redeclaration of i)

- Rajesh Manem March 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question says 3 different C files. There is a difference between what you have implemented and what is asked. Please correct me if I am wrong

- Anonymous March 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the following three statements in three statements:

int i=100;
extern int i=100;
static int i=100;

are placed into three separate files that are fed to a compiler to be compiled into a single executable, the result will be an error concerning multiple definitions of the symbol i.

The extern statement is used to give a "heads-up' to the compiler that the symbol in question is defined "externally" to the current compilation unit, in this case the file. If the variable is set to 100 in the extern statement, then there will be two definitions of the variable. One may choose to the first statement to be:
int i;
in which case the three files can compile into a single executable. If this is done, however, the compiler will give a warning that a declaration occurs in an 'extern" statement. This is appropriate since the extern statement should not reserve storate.

- Wandering programmer April 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int i=100; a.c
extern int i=100; (need not external because global var default to external) b.c
static int i=100; c.c
so a.c and b.c have multiple definition of variable i .. and c.c can use
his i (static scope is in file only );
so compile time error due to a.c and b.c

- ridercoder October 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

in trurbo c

#include<stdio.h>

int i;
extern int i;
static int i;

void main() {

printf("%d",i);
}

no compilattion error..output 0

#include<stdio.h>

int i=10;
extern int i;
static int i;

void main() {

printf("%d",i);
}

no compilattion error..output 10


#include<stdio.h>

int i=10;
extern int i=20;
static int i;

void main() {

printf("%d",i);
}

compilattion error..multiple declarations of i

- siva November 15, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More