Common C ++ written examination questions (including answers) 2

Source: Internet
Author: User

A summary of common C ++ written examination questions circulated on the Internet for reference by students who need to find a job. Because the original article is long, the serialization form is used, it is estimated that the serialization will take about 10 days. If you have patience, please keep up with us. I believe we will surely reap some benefits.

I would like to explain in advance that the questions are on the Internet, and the answers are for reference only. If any of you think you have any objection to the questions, please discuss them!

Question 11-20

11. What is the problem with the following code?
Void test3 (char * str1)
{
Char string [10];
If (strlen (str1) <= 10)
{
Strcpy (string, str1 );
}
}
= Array out-of-bounds
= The End mark of strcpy copy is to find/0 in the string. Therefore, if/0 is not encountered in the string, it will be copied until/0 is encountered, and the above 123 is out of bounds.

We recommend that you use strncpy and memcpy.
--------------------------------------------------------------------------
12. What is the problem with the following code?
# Define max_srm 256
DSN get_srm_no ()
{
Static int srm_no; // isn't the initial value assigned here?
Int I;
For (I = 0; I <max_srm; I ++, srm_no ++)
{
Srm_no % = max_srm;
If (my_srm.state = idle)
{
Break;
}
}
If (I> = max_srm)
Return (null_srm );
Else
Return srm_no;
}
The system initializes the static int variable to 0, but the value is always saved. The so-called non-reentrant...
--------------------------------------------------------------------------
13. Write the running result:
{// Test1
Char STR [] = "world"; cout <sizeof (STR) <":";
Char * P = STR; cout <sizeof (p) <":";
Char I = 10; cout <sizeof (I) <":";
Void * PP = malloc (10); cout <sizeof (p) <Endl;
}
6: 4: 1: 4
--------------------------------------------------------------------------
14. Write the running result:
{// Test2
Union v {
Struct X {
Unsigned char S1: 2;
Unsigned char S2: 3;
Unsigned char S3: 3;
} X;
Unsigned char C;
} V;
V. C = 100;
Printf ("% d", V. X. S3 );
}
3
--------------------------------------------------------------------------
15. How can I determine whether an operating system is a 16-bit or 32-bit program written in C ++? The sizeof () function cannot be used.
A1:
In a 16-bit system,
Int I = 65536;
Cout <I; // output 0;
Int I = 65535;
Cout <I; // output-1;
In a 32-bit system,
Int I = 65536;
Cout <I; // output 65536;
Int I = 65535;
Cout <I; // output 65535;
A2:
Int A = ~ 0;
If (A> 65536)
{
Cout <"32 bit" <Endl;
}
Else
{
Cout <"16 bit" <Endl;
}

--------------------------------------------------------------------------
16. What is the difference between C ++ and C ++?
Mechanism: C is process-oriented (but C can also write Object-oriented Programs); C ++ is object-oriented and provides classes. However,
C ++ is easier to write object-oriented programs than C
From the applicable direction: C is suitable for scenarios that require small code size and high efficiency, such as embedded; C ++ is suitable for upper-level and complex; llinux is mostly written in C, because it is system software, the efficiency requirement is extremely high.
From the name, we can see that C ++ is more + than C, which means C ++ is the superset of C. Why is C ++ not called C ++, because of the C ++ Ratio
C, there are too many extended things, so I put two + s behind C, so it became C ++
C is a structured programming language, and C ++ is an object-oriented programming language.
C ++ focuses on objects rather than processes, and on class design rather than logic design.
--------------------------------------------------------------------------
17. Switch the values of two parameters without using third-party parameters.
# Include <stdio. h>
Void main ()
{
Int I = 60;
Int J = 50;
I = I + J;
J = I-j;
I = I-j;
Printf ("I = % d/N", I );
Printf ("J = % d/N", J );
}
Method 2:
I ^ = J;
J ^ = I;
I ^ = J;
Method 3:
// Use addition and subtraction without Overflow
A = a + B-(B =)
--------------------------------------------------------------------------
18. Questions about bit domains (why is the output a strange character)
A. t = 'B'; the effect is equivalent to a. t = 'B' & 0xf;
'B' --> 01100010
'B' & 0xf -- & gt; 00000010
Therefore, the output ASCII code is a special character of 2.

Char T: 4; is a 4-bit character variable, the same
Unsigned short I: 8; is the 8-bit unsigned short integer variable.
--------------------------------------------------------------------------
19. Int I = 10, j = 10, K = 3; K * = I + J; what is the final value of K?
60
--------------------------------------------------------------------------
20. What are the methods for inter-process communication?
Inter-process communication methods include shared memory, pipelines, sockets, message queues, and DDE.

 

Not complete. To continue, go to "my notes" to check the next time in the serialization series!

If you want to communicate with me, welcome to the link http://student.csdn.net/invite.php? U = 113322 & C = a139a65a1494291d and I became friends!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.