C programming Flashcards

1
Q

How to find string length

A

strlen(char *);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

C++: How pair is used?

A
pair numCharPair;
numCharPair.first = 78;
numCharPair.second = 'M';
- or -
numCharPair = make_pair(78, 'M');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

C++: How to get current working directory from a running linux program?

A

getcwd(char[1024], 512);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is C++ static_cast<>

A

static_cast<> can be used to convert pointers from base class to parent class & vice versa. static_cast<> between unrelated class pointers is compilation error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to compile C++ program with C++11 support?

A

g++ -std=c++11 xyz.cpp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Show an example of pointer to a member function (method).

A

class Foo { public: int func(char x) { return 7;}

int (Foo::*fptr)(char);
fptr = &amp;Foo::func;
Foo   obj;
// Call below,
(obj.*func)('A');
Foo *p = &amp;obj;
// Call below,
(p->*func)('K');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

C++: Can a static mmbr function call non-static mmbr function?

A

A static member function cannot access any non-static members. It is a compilation error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Give example of typedef usage.

A

typedef existing_typeName new_typeName;

typedef unsigned int unsINT;

It is used to give more descriptive name to complicated types.

typedef struct student {
int roll_num;
char name[32];
} st;

st p1, p2;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Makefile ‘pattern rule’?

A

It uses % wildcard. I can only be used in target : dependency line, never in action lines.

%.wc : %.x
wc -l $.x > $.wc

all : a.x b.x c.x
This produces line number files for each .x file
$
in the action line matches with the stem of match in pattern.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Makefile: Give an example of wildcard function usage.

A

HDRS = $(wildcard src/*.h)

HDRS is a list of header files in src directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Makefile: Give an examplle of patsubst function usage.

A

HDRS = $(patsubst %.cpp, %.hpp, a.cpp b.cpp x.cpp)
HDRS is
a.hpp b.hpp x.hpp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

C++: Does catch block do type conversion?

A

No.
Exception catch block does not do type conversion.
catch(double d)
will not catch “int” exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you create a unique_ptr?

A
unique_ptr<int>  ptr1(new int);
unique_ptr<int>  ptr2(new int(47);
unique_ptr<int>  ptr3 = make_unique<int>(47);
unique_ptr<Person> p1(new Person("khan", 45));

unique_ptr<Person> p2 = make_unique<Person>("Khan", 45);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly