Deep conviction 02

Source: Internet
Author: User

One, six choice questions (can choose multiple)

1 char *p = "Hello World"; P stored in () point//Stack

Char p[] = "Hello World"; P stored in () points to

Global variables//data segments

Static variable//data segment

Where were they?

1 Data Segment 2 Code snippet 3 Heap 4 stack

(This problem can be combined with char.cpp under the same folder)

    • • (ii) Examples of procedures

It was written by a predecessor, very detailed

Main.cpp

int a = 0; Global initialization Zone

Char *p1; Global uninitialized Zone

Main ()

{

int b; Stack

Char s[] = "ABC"; Stack

Char *p2; Stack

Char *p3 = "123456"; 123456\0 in the constant area, p3 on the stack.

static int c = 0; global (static) initialization zone

P1 = (char *) malloc (10);

P2 = (char *) malloc (20);

Areas that are allocated 10 and 20 bytes are in the heap area.

strcpy (P1, "123456"); 123456\0 is placed in a constant area, the compiler may optimize it to a place with the "123456" that P3 points to.

I don't know what the tall man thinks, and I guess there should be a mistake in the middle.

2% &. && <= = That priority level is highest

. &% <= && =

3

4 which communication methods are reliable means of communication

1 Signal 2 Pipe 3 message 4tcp 5UDP 6 serial I/O

5 is (M)? (a++): (a--), here M equals I choose c

a,m==o,b,m==1,c,m! =o,d,m! =1

6 is the start Order of UNIX sequencing. (6 options)

Two

1 is the system conversion of 151 to 2 and nine binary. 10010111 177

2 Known 0 ASCII code is 0x40, then int 120; In memory the representation is 0x__ 78 (0 ASCII code is 0x40, should be 0x30)

3

1. Under Linux, the command to view the directory size is:

2. The command to modify the properties of a file is:

3. The command to switch to another user's identity is

4 There is also a pointer exchange value int i=0,j=10,int* p=&i, int* q=&j,

int Fun (**A,*B)

{int* temp=a;

*a*=10;

*b*=10;

A=b;

B=temp;

The final question called fun (&P,Q) asks the final value of the I, J, p, Q (the exact form is probably the case, but the intermediate pointers definitely remember the error)

This topic mainly examines the pointer to an integer, then uses the pointer to change the variable, the last Exchange pointer

5 Youdao fill in the algorithm of the sorting. There is an array a[0] to a[i-1] for small to large sort, a[i]

Ount-1] No sort, please add 3 statements so that they are sorted from small to large

int insert_sort (int a[],int count)

{

for (int i=1;i<count;++i)

{

int j,t;

T=a[i];

(j=i-1;)

while (J>=0&&t<a[j])

{

(A[j+1]=a[j];)

j--;

}

(a[j+1]=t;)

}

return 0;

}

Three, programming and logic problems

1 Write a strstr yourself

(Single-linked list is judged to have no ring,)

char* strstr (char* buf, char* sub)

{

char* BP;

Char* sp;

If (!*sub)

return buf;

while (*BUF)

{bf=buf;

Sp=sub;

do{if (!*SP)

return buf;

}

To A[c

while (*bp++==*sp++)

Buf+=1;

}

return 0;

}

2 Traverse text to find a word and delete the word with the least frequency, fun (char* ptext) #include <stdio.h>

#include <stdarg.h>//define macros such as Av_list, Av_start, Av_arg, etc.

3 Implementing a function similar to the printf function ·

#include <iostream>

#include <conio.h>

#include <stdio.h>

#include <stdarg.h>//define macros such as Av_list, Av_start, Av_arg, etc.

/******************************************************************* the function:

Implement a function with a variable number of arguments, which functions like printf,

But in format processing, it's not as rich as printf

No exception, returns a true, otherwise returns false

The legal status of the format string is as follows:

1. "%%zyk%%zyk%%", output:%zyk%zyk%

2. "%dzyk%fzyk%s", OUTPUT: (int) Zyk (float) Zyk (string)

3. "Zyk", Output:zyk

The illegal situation is as follows:

1. "%zyk%" ERROR: There is no%z format, the% must follow a format character

/bool Zykprintf (const char * format,...)

{

Defines a pointer that can be used to point to a parameter (real char *).

Va_list argptr;

Pass the address of the first parameter of the function format to Argptr

Va_start (Argptr,format);

const int size = strlen (format) +1;

Char *tmp = new Char[size];

memset (tmp, 0, size);

    • ·

{while (*format! = 0)

int i;

for (i=0; i<size && *format!= '% ' && *format!=0; i++)

{

tmp[i]=*format++;

}

Tmp[i] = 0; 0-value protection at the end of a valid string

printf ("%s", TMP);

if (*format = = 0)

return true;

Switch (*++format)

{

Reads the next parameter by the specified type and prints

Case ' d ': {printf ("%d", Va_arg (argptr, int));

Case ' s ': {printf ("%s", Va_arg (Argptr, char *));

Case ' C ': {printf ("%c", Va_arg (Argptr, char));

Case ' F ': {printf ("%f", Va_arg (argptr, float));

The processing of the percent

Case '% ': {printf ("percent"); break;}

Format error

Default: {printf ("Error ocurr! Please Check the format! "); return false;}

}

++format;

}

Delete[] tmp;

return true;

}

int main (int argc,char * argv[])

{

zykprintf ("%zyk"); Error

zykprintf ("zyk%"); Error

zykprintf ("%%zyk%%zyk%%"); OUTPUT:%zyk%zyk%

zykprintf ("\nzyk is a pretty boy! His was%d and%s ", 5," I Love Zyk ^_^! ");

Getch ();

return 0;

}

4 is a logical problem, and some of the number is a multiple of 2,3,5, in the three-digit number can be divisible by the number of the three and ·

4th/8 Page

(5 liters and 3 liters of barrels 4 liters of water)

Four, change the wrong question three way

1tozero algorithm

2 relatively simple

3 is a problem in high quality.

Five, ask questions

What are the methods in 1VC to avoid the duplication of header files in C programming:

#ifndef!!!!

#def!!!!

#endif

2 The role of extern C in C + +

(Key conversion, e.g. click P output Q)

As extern is a keyword that indicates the scope (visibility) of functions and global variables in the C/s + + language, which tells the compiler that its declared functions and variables can be used in this module or in other modules.

extern "C" is a connection declaration (linkage declaration), and the variables and functions modified by extern "C" are compiled and concatenated in C language.

3 What is the difference between asynchronous IO and synchronous IO in programming? Tell me about some of the IO you may know?

4 use asynchronous socket programming, usually because the network congestion send data, what kind of error code (under Windows example), usually how to deal with this situation?

(The core is too different from the user, x86 how to convert.) )

5 porting the program to a different 32-bit CPU, often the structure of the byte alignment and size of the problem, there are some ways to avoid it?

(is the subnet source of the judgment, calculation, ABCDE network difference, the use of De network,)

6 How to solve the problem of memory leak in VC (release version)

(1) Position keyword assert ()

(2) Generate a map file. It does not add anything to the EXE file, it simply records all the function entry addresses when the connection was compiled in the suffix. map file. When the program crashes, you can get an EIP address at the time of crash, where the function of the crash can be easily traced through the address. (In VC setting, there is a link button selected Generate Mapfile)

(3) Release version can also set breakpoints, add _asm int 3 at the point where you want to set a breakpoint

(4) familiar with the assembly, through the compilation of compile-time see

(5) Use a third-party debugger.

(6) Turn off some of the optimization options in the release to generate debug information.

(It is the principle that peer-to software implements data transmission in NAT users.)

The development of the written test is C + +, requires a certain understanding of the bottom level of the written test of the problem of the faint, a total of five pages of paper, two completed (my resume did not pass the screening, I was to the-_-pen) as if the content of the test is similar to the online circulation, the topic content is as follows: Hope to take part in the deep conviction of the written examination and interview students are helpful:)

1. Select Title: 6 The first question is the test variables and the value of the storage location (heap/stack/code segment/Data section, etc.) the last question is the UNIX system boot sequence, the other several problems are relatively simple.

2. Fill in the blanks: 4/5 test sizeof, pointers, the conversion of the numbering, sorting, etc., have seen high-quality C + + should be no problem.

3. Wrong title: 3 problem with high-quality C + + in a pointer to a similar problem, but there is no mistake in the problem, originally did not need to modify, but instead I changed the wrong, Khan ... The other two questions are relatively simple.

4. Programming Questions: 4/5 judgment linked list has no ring (requires two methods); implement printf in C

5th/8 Page

Several vc/mfc written questions of a company in Shenzhen (including reference answers)

How to solve the bug of memory leak and illegal operation under 1:release version. (Do not know what illegal operation)

2: In asynchronous socket, why do not send data sometimes, what error will be reported (sub-windows/linux), you generally how to deal with?

Here are a few of the programming

3: Implement the STRSTR model (I faint, I wrote a function, just not strstr, but STRCHR)

4: Implement printf-like functions, void myprintf (char *str,...)

(with the console API?) It seems like in which book to see the implementation of those APIs, hey, I wrote a std::cout<< 5: Delete the text file in the smallest occurrence of the word, (the file with a space to indicate a word interval)

void func (char *ptxt)

1, the realization of STRSTR prototype.

Char *my_strstr (const char *STR, const char *strsearch)

{

while (*str! = ')

{

Char *p = (char *) str;

Char *ps = (char *) strsearch;

while (ps && *p = = *ps)

P, PS;

if (' + ' = = *ps)

Return (char *) str;

STR;

}

return NULL;

}

2. Delete the word with the fewest frequency from the specified text, if there are more than one, delete it. Implement the void Func (char* pTxt) function.

... Look at word processing, many of the forums have involved

3, the implementation of printf.

int printf (const char *format, ...)

{

Va_list arglist;

int buffing;

6th/8 Page

int retval;

Va_start (arglist, format);

_ASSERTE (Format! = NULL);

#ifdef _MT

_LOCK_STR2 (1, stdout);

__try {

#endif/* _MT */

buffing = _stbuf (stdout);

retval = _output (stdout,format,arglist);

_ftbuf (buffing, stdout);

#ifdef _MT

}

__finally {

_UNLOCK_STR2 (1, stdout);

}

#endif/* _MT */

return (retval);

}

4, VC in what ways to avoid the C compiler header file duplication. (except #ifndef/#define/#endif外, I can't think of it)

#pragma once

5, the use of extern "C".

Used to provide C interfaces, such as the use of C naming methods.

6, asynchronous socket programming, send the data error code is what, (for example, Linux or Windows), how do you deal with it?

There are 2 reasons for non-blocking socket,send data, and TCP is disconnected and the socket is in a blocked state (that is, in sending data). The UPD does not send out only TCP behind the situation.

The way to do this is to record the state of the socket, when the status is blocked time, put the buffer, when the socket can be written again, send.

7. What is the difference between asynchronous IO and synchronous IO? What are some examples (such as read)?

7th/8 Page

Asynchronous IO does not necessarily complete the IO operation when the function returns, and the synchronization Io is complete. So asynchronous IO requires an event that is set when the IO is complete and the caller waits on the event.

In 8, 32-bit system, the problem of structure byte alignment and the problem of size end are avoided.

#pragma pack (4)

9, how to detect the memory leaks and illegal operation of the bug (under Release version)?

Using the Map file

1, PostMessage only put the message in the queue, regardless of whether the other program is processed to return, and then continue to execute, this is an asynchronous message delivery function. The SendMessage must wait for the other program to finish processing the message before returning, continue execution, this is a synchronous message delivery function. Also, the return value of PostMessage indicates that the PostMessage function was executed correctly, and the return value of SendMessage represents the return value of the message after the other program processed it. We should all understand this point.

2, if PostMessage sends a message within the same thread, the message is first placed in the thread's message queue and then dispatch through the message loop to the target window. When SendMessage sends a message, the system calls the target window's message handler directly and returns the result. SendMessage sends a message in the same thread and does not enter the thread message queue. If it is within a different thread. Most useful

PostThreadMessage instead of PostMessage, he works very well. SendMessage sends a message to the message queue of the thread that the destination window belongs to, and then waits for the thread to send the message (in fact, he should still be doing some monitoring work, such as monitoring the QS_SENDMESSAGE flag) until the target window finishes processing and the result is returned, and the line friend to send the message continues to run. This is the general case of SendMessage, in fact, the process is much more complex. For example, when the thread that sends the message detects a different window SendMessage a message arrives, he calls the window processing (re-entry) directly and returns the processing result (this process does not require support for getmessage in the message loop).

3, msdn:if you send a message with the range below Wm_user to the asynchronous message functions (PostMessage, Sendnotifyme Ssage, and Sendmessagecallback), its message parameters can not include pointers. Otherwise, the operation would fail.

If the message code being sent is below Wm_user (not a custom message) and the message parameter has pointers, then postmessage,sendnotifymessage,sendmessagecallback these asynchronous message send functions will fail. It is best not to use PostMessage to send messages with pointer parameters.

The main difference between PostMessage and SendMessage is whether to wait for other program message processing. PostMessage just puts the message in the queue, regardless of whether the other program returns, and then resumes execution, and SendMessage must wait for the other program to process the message before returning and continuing. The return values of the two functions are also different, and the return value of the PostMessage indicates that the PostMessage function is performing correctly, and the return value of SendMessage represents the return value of the other program after the message was processed.

Deep conviction 02

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.