0 like 0 dislike
29 views
in Computer Science by (1.0m points)
Write the difference between declaring and defining a variable.

1 Answer

0 like 0 dislike
by (1.0m points)

In C and C++, there is a subtle but important distinction between the meaning of the words declare and define. If you don't understand the difference, you'll run into weird linker errors like "undefined symbol foo" or "undefined reference to 'foo'" or even "undefined reference to vtable for foo" (in C++).

What it Means to Declare Something in C and C++

When you declare a variable, a function, or even a class all you are doing is saying: there is something with this name, and it has this type. The compiler can then handle most (but not all) uses of that name without needing the full definition of that name. Declaring a value--without defining it--allows you to write code that the compiler can understand without having to put all of the details. This is particularly useful if you are working with multiple source files, and you need to use a function in multiple files. You don't want to put the body of the function in multiple files, but you do need to provide a declaration for it.

Related questions

0 like 0 dislike
1 answer 20 views
0 like 0 dislike
0 answers 32 views
0 like 0 dislike
1 answer 49 views
0 like 0 dislike
1 answer 47 views
0 like 0 dislike
1 answer 43 views
asked Dec 12, 2018 in Geography by danish (1.0m points)
0 like 0 dislike
1 answer 36 views
0 like 0 dislike
1 answer 62 views
0 like 0 dislike
1 answer 18 views
0 like 0 dislike
1 answer 23 views
0 like 0 dislike
1 answer 24 views
Welcome to Free Homework Help, where you can ask questions and receive answers from other members of the community. Anybody can ask a question. Anybody can answer. The best answers are voted up and rise to the top. Join them; it only takes a minute: School, College, University, Academy Free Homework Help

19.4k questions

18.3k answers

8.7k comments

3.3k users

Free Hit Counters
...