A collection of written examination questions of a Heavy Industry Enterprise (with answers)

Source: Internet
Author: User

Because of the confidentiality issues, I will not specify what company it is. In short, it is very big. Let's take a look at it. It is quite basic and practical.


1. # ifndef/# define/# endif in the. h header file?


A: prevent this header file from being repeatedly referenced.

2. # define double (x) x + x

Int I = 5 * double (5 );

The value of I is

A: 30

3. For a 32-bit system, the C ++ program is described and defined as follows:

typedef union {int i; int k[5]; char c;} DATE;struct data { char cat; DATE cow; int dog;} too;

The execution result of the statement printf ("% d", sizeof (too); is :______


Answer: 28

4. In some cases, an endless loop is required. Which of the two loops for (;) and while (1) is more efficient (the compiled code is shorter )?


A: (;;)

5. What are at least ______ nodes in a balanced binary tree with a height of 8?


Answer: 54

6. In a 32-bit system, calculate the sizeof value for the c ++ program.

Char STR [] = "www.ibegroup.com"; char * P = STR; Calculate sizeof (STR) = _ ① ___ sizeof (P) = ___ ② ___ void Foo (char STR [100]) {calculate sizeof (STR) = ___ ③ ___} void * P = malloc (100); Calculate sizeof (P) = ___ ④ ___


Answer: ① 17 ② 4 ③ 4 ④ 4

7. How does Winsock establish a TCP connection?


A: On the server side: socket () creates a socket, binds (BIND), listens (Listen), and uses accept ()

Wait for the client connection. When a client connection is found, a new socket is established and the connection is restarted. The new socket uses send () and Recv () to write and read data, call closesocket () to close the socket after data exchange is complete.

Client: socket () is used to establish a socket and connect to the (CONNECT) server. After the connection, send () and Recv () are used to write and read data on the socket until the data exchange is complete and closesocket () is called () close the socket.

8. answer the following questions:

(1) What are the results of running the test function?

void GetMemory(char **p, int num){*p = (char *)malloc(num);}void Test(void){char *str = NULL;GetMemory(&str, 100);strcpy(str, "hello");printf(str);}

A: Output hello.

(2) what are the results of running the test function?

char *GetMemory(void){char p[] = "hello world";return p;}void Test(void){char *str = NULL;str = GetMemory();printf(str);}

A: The pointer is invalid and the output is uncertain.

10. The following functions are available:

int func(int x) {     int countx = 0;     while(x)     { countx ++; x = x&(x-1); }     return countx; }

Q: The Return Value of func (9999) is ______


Answer: 8

11. Read the function description and C functions to complete the C functions.

[Function 1 description]
The palindrome (chars []) function is used to determine whether string S is a return string. If so, 0 is returned; otherwise,-1 is returned. If a string is the same as a forward and backward read, it is called a return string. For example, "level" is a return string, but "leval" is not.

[Function 1] int palindrome (char s []) {char * Pi, * PJ; Pi = s; PJ = S + strlen (S)-1; while (pI <PJ & (①) {PI ++; PJ --;} If (②) Return-1; else return 0 ;} [function 2 Description] function f (char * STR, char del) is used to split a non-empty string STR into several sub-strings and output the results. Del indicates the flag character during splitting. For example, if the STR value is "33123333435" and the del value is '3', after this function is called, three sub-strings are output, they are "12", "4", and "5" respectively ". [Function 2] void F (char * STR, char del) {int I, j, Len; Len = strlen (STR); I = 0; while (I <Len) {While (③) I ++; /* ignore consecutive flag characters * // * Find a substring starting from STR [I] until the flag character appears */J = I + 1; while (STR [J]! = Del & STR [J]! = '\ 0') J ++; ④ =' \ 0';/* end string sign */printf ("% s \ t ", & STR [I]); ⑤ ;}}


A: ① * Pi = * PJ ② pI <PJ or * Pi! = * PJ

③ STR [I] = del ④ STR [J] ⑤ I = J + 1

12. Use C/C ++ to implement the void swap (float * a, float * B) function. Requirements: ① the function can be called externally to exchange the values of two float variables; ② The function swap cannot use the third variable.

A: void swap (float * a, float * B) {* A = * A + * B; * B = * A-* B; * A = * A-* B ;}

13. The node Structure of a linked list is as follows:

Struct Node


Int data;

Node * next;


Typedef struct node;

If the head of the head node of the linked list is known, write a function node * reverselist (node * head), which requires that the list be sorted in reverse order.


A: node * reverselist (node * head) {If (Head = NULL | head-> next = NULL) return head; node * P1 = head; node * P2 = p1-> next; node * P3 = P2-> next; P1-> next = NULL; while (P3! = NULL) {P2-> next = p1; P1 = P2; P2 = P3; P3 = P3-> next;} P2-> next = p1; head = P2; return head ;}



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.