Lenovo pen exam

Source: Internet
Author: User

Lenovo pen questions-if you need to reprint, please indicate the source, thank you! 1. design function int atoi (char * s ).Int atoi (Char *S )
{

Char sign ;
Char sign_val =1 ;
Int Val =0 ;
Int n =0 ;

/* Skip Spaces */
While(Isspace(*S))
++
S;
If(*S='-'| *S='+')
/* Skip '-' and '+ 'sign */
{
Sign= *S;
If(Sign='-')
Sign_val=-1;
++
S;
}

/* When goes here, it is not space or sign */
While((*S! ='/0')&&Isdigit(*S))
{

Val=10*N+ (*S-'0');
N=Val;
S++;
}

If(*S! ='/0')
{

Printf("Non digit in your input !! /N");
Exit(-1);
}

/* Non error occured */
Return(Sign_val*Val);
}
2. Int I = (j = 4, K = 8, L = 16, M = 32); printf ("% d", I); what is the output?
Result: 32.3. Explain the meanings of local variables, global variables, and static variables. Local variables include the form parameters of the function and the variables contained in the function body or statement block. The survival of local variables ends after exiting the function or statement block. A global variable is a variable other than all function and statement blocks. It can be seen in the entire program. The lifetime of a global variable is the same as that of a program. A static variable is a variable declared by the keyword "static". Its scope is the same as that of other variables and is determined by its location. For example, a static variable is declared in a function body or statement block, it is visible only in the function body or statement block, but not in other places.
It has the same lifetime as the program.4. explain the difference between stack and stack.The description is as follows:
The memory allocated on the stack is automatically allocated by the system and will be automatically withdrawn by the system.
To dynamically allocate memory, you can only use malloc/New to allocate memory on the heap,
After use, use free/Delete to release the memory.5. Discuss the advantages and disadvantages of macros and functions with parameters.Macro advantages with parameters:
Saves the overhead of function calls and runs efficiently.
Disadvantages of parameters:
The macro is essentially a string replacement, and all values may be obtained due to the side effects of some parameters.
Incorrect result.
For example:
# Define max (A, B) (a)> (B ))? (A): (B ))
If such a call occurs in the program: max (A ++, B );
This will cause a to be calculated twice, which may lead to incorrect results. function calls will not encounter this problem. in addition, if there are multiple macro replacements in the program, the code size may increase. functions have the following advantages:
There are no side effects that may be caused by macros with parameters. The correctness of the calculation is more reliable than that of macros.
Disadvantages of function calling:
Function calls require some parameters, return addresses, and other inbound stack. the overhead of the outbound stack is not as efficient as macro functions.

Come
Http://blog.chinaunix.net/u/19481/showart_138359.html

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.