Digital Video 2015 school recruit written test C + + Simple Summary

Source: Internet
Author: User

Both of them look at the code, and then find the error in the code and make an explanation.

Topic One
int array[] = {1,2,3,4,5,6}; #define ELEMENTS (sizeof (array)/sizeof (array[0)) int main () {           int d =-1, x;        for (int i = D; i< elements-1; i++)        x = array[1];        cout<< x;}

misunderstanding: This article mistakenly thought #define that part of the error. Think elements can not find the length of the array, the result will be 1. There is a misunderstanding here, that is, when the sizeof array, the total size of the array is returned or the size of the head pointer.

The right answer: There are eyes who can make the answer. The error is that when looping, the i<elements-1 return value will be false and the assignment operation in the loop body is not performed. The reason for this is that the return value of the sizeof operator is size_t, which is generally the unsigned int type. So, the last X is output without initialization.

Topic Two

The topic is too long, too lazy to fight.
The point is that

char* localtime (char* filename) {    ...    Char buffer[120];    ... return buffer;}

This is just one of the points of attention.

I failed ...

Digital Video 2015 school recruit written test C + + Simple Summary

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.