You are here:

C/Declaration and Definition.

Advertisement


Question
In my technical interview in Robert Bosch they asked  me this question.
int a;
is this a declaration or definition ?
i said it is a definition because memory is allocated  to it & some garbage value is asssinged to it.But he said it is wrong.
if it is a declaration please tell me how it is?

Answer
It is both a declaration and definition.
Nothing is assigned to it. That's why you see some garbage when you print the value.
In case of variables, "extern int i;" is the only place where it is declared, but not defined.
In all other cases it is both declared and defined.

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.