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

Does improper inheritance have a potential to wreck a project?

0 Answers  


How to allocate memory dynamically for a reference?

0 Answers  


Find out the bug in this code,because of that this code will not compile....... #include <iostream> #include <new> #include <cstring> using namespace std; class balance { double cur_bal; char name[80]; public: balance(double n, char *s) { cur_bal = n; strcpy(name, s); } ~balance() { cout << "Destructing "; cout << name << "\n"; } void set(double n, char *s) { cur_bal = n; strcpy(name, s); } void get_bal(double &n, char *s) { n = cur_bal; strcpy(s, name); } }; int main() { balance *p; char s[80]; double n; int i; try { p = new balance [3]; // allocate entire array } catch (bad_alloc xa) { cout << "Allocation Failure\n"; return 1; }

2 Answers   Impetus,


What are the two shift operators and what are their functions?

0 Answers  


Why c++ is better than c language?

0 Answers  


Explain how a pointer to function can be declared in C++?

0 Answers  


Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == ) y-= 7; else y = 8; if the value of x is 4 before the nested IFs are executed, what is the value of y after the nested IFs are executed?

0 Answers  


What is time_t c++?

0 Answers  


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

0 Answers  


How to construct virtual constructor

6 Answers   CIStems Software, Symphony,


How to reduce a final size of executable?

3 Answers  


What is encapsulation in C++? Give an example.

0 Answers   HAL, Honeywell, Zomato,


Categories