Namespaces Namespaces allow to group entities like classes, objects and functions under a name. This way the global scope can be divided in "sub-scopes", each one with its own name.The format of namespaces is:namespace identifier{ entities}Where identifier is any valid identifier and entities is the set of classes, objects and functions that are included within the namespace. For example:1234 namespace myNamespace{int a, b;}In ...
Sunday, March 28, 2010
Monday, March 8, 2010

The C preprocessor is a program that processes our source program before it is passed to the compiler.preprocessor is a separate program which transforms C source code containing preprocessor directives into source code with the directives removed.The preprocessor is implemented as an integral part of an Standard C compiler.gcc -E filename will show...
1.Macro Expansion: * C preprocessor provides a facility for defining constant and substitution,which are commonly called macros. * Macros are used when we want to make a program more readable or when we dont have enough information about certain values. * A macro definition has the form #define name replacement text * The statement above define a macro and some replacement text.The preprocessor will replace the name with the replacement...
Operators in Preprocessor: * The 2 operators used in the preprocessor are 1. # 2. ##1.# operator: * If the macros are present with in the quoted strings it is not replaced by the #defined macro. * But if the macroname is preceded by a # then the macro is expanded into a quoted string with the parameter replaced by the actual argument * Eg: #include #define toprint(expr) printf(#expr "=%d\n",expr) int main() { int...
1.What is the output of the following program?#include#define clrscr() 10int main(){ printf("result=%d\n",clrscr()); return 0;}result=10#defines are used for textual replacement2.What is the output of the following program?#include#define fun(f1,f2) f1##f2int main(){ int some100=100; printf("result=%d\n",fun(some,100)); return 0;}Solutionresult=100To know about the ## operator Click here3.What is the output of the following program?#include#define...
Thursday, February 25, 2010
Q 16.)#includeusing namespace std;class Base {public:Base(){foo();}virtual void f(){cout << "\nBase::f is being called\n";}void foo(){f();}};class Derive : public Base {public:virtual void f(){cout << "\nDerive::f is being called\n";}};int main(){Derive d; //Base::f is being called.. f being virtual.. Why derived f() is not being called..}why output is not expected..Q.17)int main(){int i=10, j=2;int *ip= &i, *jp = &j;int k = *ip/*jp;printf("%d",k);return...
Wednesday, February 24, 2010
Q 11.)
Is there a way to multiply two matrix in less than O(n^3) time complexity..
For this Q algorithm was asked, if you guys don't know the answer then make a comment below and I will tell the answer or just take some efforts to search it.
Q 12.)
#include
using namespace std;
int main()
{
int a,c,foo;
char *p;
cin>>a>>c;// give two numbers..
p=(char *)a;
foo= (int)&p[c];
cout<foo; return 0;
}
what this code snippet does...
even...
Q 6.)#include int main(){int a=3, b = 5;printf(&"Ya!Hello! how is this? %s\n"[a], &b["junk/super"]);printf(&"WHAT%c%c%c %c%c %c !\n"[a], 1["this"],2["beauty"],0["tool"],0["is"],3["sensitive"],4["CCCCCC"]);return 0;}is this a valid c program....Q 7.)The following C program segfaults of IA-64, but works fine on IA-32.int main(){ int* p;p = (int*)malloc(sizeof(int));*p = 10;return 0; }Why does it happen so?Q 8.)#include #define f(a,b) a##b#define...
Q1.)#include#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))int array[] = {23,34,12,17,204,99,16};int main(){signed int d;printf("Total Elements in the array are => %d\n",TOTAL_ELEMENTS);for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)printf("%d\n",array[d+1]);printf("Did u see the output..");return 0;} Q 2.) File1.c 1 int arr[80]; File2.c extern int *arr;int main(){arr[1] = 100;return 0;}what should be the output.. Q 3.) #includeint main(){int...
Subscribe to:
Posts (Atom)