A file a.cpp & B.cpp are complied & linked together in VC++
file a is something like int a =100;, File B is something
like extern a;
main()
{
printf("%d",a);
}what will be the output.a)100,b)linker error,c)complier
error etc etc.

Answer Posted / shankar

Take an example, if you are working on a C++ project but it
also deals with some existing C functions/libraries.
You want to wrap them in a C++ module or compile them with
other C++ objects without any C++ compiler errors, then you
would declare the C function prototypes in an extern "C"
block to notify the compiler that they would be compiled
along with other C++ functions into one module.

For example:

my_C_CPP_Header.h:

#ifndef MY_C_CPP_HEADER
#define MY_C_CPP_HEADER


/*check if the compiler is of C++*/
#ifdef __cplusplus
extern "C" {
int myOtherCfunc(int arg1, int arg2); /* a C function */
}
#endif

void myCppFunction1(); /* C++ function */
void myCppFunction2(); /* C++ function */

/*check if the compiler is of C++ */
#ifdef __cplusplus
}
#endif

#endif


Now all three functions are comiled into one module by C++
compiler.

So the out put is (a)100.

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between turbo c++ and visual c++?

534


How do I remove microsoft visual c++ 2015 redistributable?

588


What is microsoft visual c++ 2015 redistributable package x64?

560


What is visual c++ runtime error?

603


What is visual c++ runtime?

589






Explain the advantages of cwinthread class.

604


how to declare and populate an array of checkBoxes

683


What is the use of message map? Advantages of a message map.

587


Do I need microsoft visual c++ on my computer?

589


What is microsoft visual c++ 2017 redistributable?

547


How do I change visual code font?

594


What is vcredist_x86 exe?

612


What is microsoft visual c++ 2008 redistributable?

587


How do I install microsoft visual c++ 2015?

537


Do I need microsoft visual c++?

573