面试时最经常被问到的问题(Frenquently asked interview questions)之C/C++篇[6]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 mxclxp 的 blog

why? because x will be incremented after y = y+x has been carried out and result has been assigned to y.
if it would have been y+=++x then the value of y would have been equal to 13 and x = 6
i am sure about this
mohit

19what's the difference between c and c++?

c is top down approach
c++ is bottom up programming approach.

c does not support oop (object oriented programming) and do not support polymorphism, inheritence, encapsulation, function overloading.

there is an important difference but often neglected by many people is the error handling.

some common c style commands and there corresponding c++ style commands are shown below.


console i/o
***********
c
===
printf("hello world!\n");
scanf("%s", name);
c++
===
cout << "hello world!"
<< endl;
cin >> name;

comments
********
c
===
/* comment */
c++
===
// comment

file extensions
***************
c
===
.c, .h
c++
===
.c, .h, .cpp, .hpp

file i/o
*********
c
===
out = fopen("output_file.dat", "wb");
in = fopen("input_file.dat", "rb");
c++
===
ofstream out("output_file.dat");
ifstream in("input_file.dat");

dynamic memory
**************
c
===
text = (char *) malloc(1000);
free(text);
c++
===
text = new char[1000];
delete [] text;

constants
*********
c
===
#define pi 3.14159
c++
===
const float pi = 3.14159;

macros
******
c
===
#define max(a,b) ((a) > (b) ?
(a) : (b))
c++
===
inline int max(int a, int b) { return a > b ? a : b; }


20what does public and private mean in c++

--public:
makes class memebrs accessible outside the class. it can be accessed in the c code.
private:
makes the members specified accessible only to the class and it's functions.
--public / private have two different meanings in c++:
1. to specify the access privilege of the class members.

本文关键:面试时最经常被问到的问题(Frenquently asked interview questions)之C/C++篇
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top