If we declare two macro with the same identifier without
doing undef the first, what will be the result?
eg: #define MAX_SIZE 100
#define MAX_SIZE 200

int table1[MAX_SIZE];

Answers were Sorted based on User's Feedback



If we declare two macro with the same identifier without doing undef the first, what will be the r..

Answer / ahmed

It will be 200
This is why #define is considered as unsafe type when
compared to const variables

Is This Answer Correct ?    9 Yes 0 No

If we declare two macro with the same identifier without doing undef the first, what will be the r..

Answer / binoy mathew

#include <iostream>
#include <stdlib.h>

#define max 100
#define max 200

int main()
{
printf("%d",max);
return 0;
}

save and run.

[root@localhost Desktop]# g++ test.cpp
test.cpp:5:1: warning: "max" redefined
test.cpp:4:1: warning: this is the location of the previous
definition
[root@localhost Desktop]# ./a.out
200

it shows a warning, but the value used is the latest.

Is This Answer Correct ?    1 Yes 0 No

If we declare two macro with the same identifier without doing undef the first, what will be the r..

Answer / sourisengupta

Thanx Ahmed

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

Difference between delete and delete[]?

5 Answers   Infosys, TCS, Virtusa,


How do we balance an AVL Tree in C++?

0 Answers   Impetus,


What is the difference between public, private, and protected access?

0 Answers  


How can you quickly find the number of elements stored in a dynamic array?

0 Answers  


What is the importance of mutable keyword?

0 Answers  






Are there any special rules about inlining?

0 Answers  


What is meant by entry controlled loop? What all C++ loops are exit controlled?

0 Answers   TCS,


What is the latest version on c++?

0 Answers  


Can we make any program in c++ without using any header file and what is the shortest program in c++.

0 Answers   MCN Solutions,


What is rvalue?

0 Answers  


Which uses less memory? a) struct astruct { int x; float y; int v; }; b) union aunion { int x; float v; }; c) char array[10];

4 Answers   Quark,


Describe the main characteristics of static functions?

1 Answers  


Categories