היה לי ריאיון בג'יגה, מבחן ב-C/++C להלן רוב השאלות, לא קשות, סתם מעצבנות: בהצלחה!!!
סורי על האינדנטציה
1) int x=5
what are the values X can have after running this code, assuming the compiler is optimised
if ((a<10) || (a>9) || ++x) x--;
answer:
4
2) the same as above, but this time:
if ( (a>9) || ++x) x--;
answer:
4 or 5
3) what will be printed:
int main()
{
int i=32, j=4, k, *q;
k=--i/j;
q=&j;
{
int i,j=10;
i=j- ++(*q);
printf(""i=%d, j=%d\n", i, j);
}
printf(""i=%d, j=%d\n", i, j);
return 0;
}
answer:
i=5 j=10
i=3, j=5
4) chat st={"abcd"};
sizeof(st) = ?
answer: 5
5) what is x in both cases?
int x = (7&2) | 4
int x = (7&&2)||4
answer:
6
1
6)a. x=10
x=x<<2
x=?
b. x=10
x=x>>2
x=?
answer:
a. 40
b. 2
7)
int arr = {10,20,30,40,50}
printf("%d\n", *(arr+2));
printf("%d\n", *(&arr+3));
printf("%d\n", *((char *)(arr+4)));
printf("%d\n", *((char *)arr+4));
answer:
30
50
50
20
int arr = {10,20,30,40,50}
int *p = {&arr, &arr, &arr};
int *pp;
pp=p;
printf("%d\n", **pp);
pp++;
printf("%d\n", **pp);
printf("%d\n",++**pp);
answer:
10
20
21
9) איפה נוצר משתנה גלובליי/סטטי בתוכנית, האם על הסטאק או על ההיפ?
10)
class cl
{
public:
int prm;
cl(int prm);
};
cl::cl(int prm) {prm = prm;}
what will happen?
answer:
the value in prm is not defined
11)
derived is derived from class basis, both classes have the function int func()
which function will be called?
basis *b = new derived;
b->func();
12) the same as the above, but now func is virtual
13) what is the output?
class base
{
public:
static int x_m;
base() {x_m++;}
~base() {x_m--;}
};
int base::x_m = 0;
void main()
{
base a;
cout<<a.x_m<<endl;
{
base b;
base c;
cout<<base::x_m<<endl;
}
cout<<a.x_m<<endl;
}
answer:
1
7
1
14) what will be printed?
template <class T1, class T2>
int getx(T1 a, T2 b)
{
int result;
result = (sizeof(a)>sizeof(b))?sizeof(a);sizeof(b);
return result;
}
class sclass
{
public:
int length;
int width;
int depth;
sclass():length(1),width(2),depth(3){}
};
typedef struct
{
int k;
char l;
} strc;
void main()
{
sclass s1;
strc m = {3, 'a', 'b', 'c', 'd'};
int i=5;
int j=1;
cout<<getx(i,j);
cout<<getx(i,m);
cout<<getx<int,double>(3,4);
cout<<getx(s1,m);
}
answer:
4
8
8
12