Hot answers tagged

3 votes

Why do macros take more space than an equivalently defined function?

The plain and simple truth is: Macros are NOT stored directly in memory.(during program execution and/or compiling) What happens is, that, the values are copied from the macro to where you used the ...
  • 1,146
3 votes
Accepted

Why do macros take more space than an equivalently defined function?

A function is identified by an entry point (address) inside the executable code. You use a function from different parts of your code. If you use a macro, the object code of that macro is substituted ...
  • 1,156
1 vote

Why is const used in field.c of pset3?

No they are not the same: #define MAX 65536: This tells the compiler to swap all instances of MAX with 65536, it is not not a variable that exists in memory. const int MAX = 65536: This declares a ...
  • 1,223
1 vote

Whats's difference between declaring and defining variables?

when you #define DIM_MIN 3, you are defining a constant not a variable. what's the difference? well, there are many differences actually, but probably the most important one is that, in case of a ...
  • 17.4k
1 vote
Accepted

Whats's difference between declaring and defining variables?

You can use these values throughout your entire code, but you cannot change their values. Therefore it's a useful tool for creating global constants in your code. A bit more info: #define DIM_MIN 3 ...
1 vote

Excess elements in scalar initilizer?

By doing int example[]; you are initializing a pointer to an array whose size is not defined. After that in int example = {1,2,3}; yu are adding values to the pointer which is illogical and has no ...
1 vote

Excess elements in scalar initilizer?

You have to set the size of the array. I.E: int example[10]; then you could do this to set the first element of the array to 1: example[0] = 1; You can't do this though: int example[10]; example ...
  • 11
1 vote

Declaration and Initialization gives error: unused variable

You never really used k in main after you've declared it. This error is actually caused by passing the -Werror option on compilation which is responsible for turning warnings to errors. To fix that ...
  • 17.4k

Only top scored, non community-wiki answers of a minimum length are eligible