Interesting IT interview questions and interesting IT interview questions

Source: Internet
Author: User

Interesting IT interview questions and interesting IT interview questions


A piece of C code looks simple, and the expected result is the output array.

#include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};
int main()
{
	int d;
	for(d = -1;d <= (TOTAL_ELEMENTS - 2); d++)
		printf("%d\n", array[d+1]);
	return 0;
}

After the code is compiled and run, the result is not the desired array, but a null value. Many people will think of macro definition, because macro definition cannot obtain the length of the array.

But we can change the for loop to different results.

for(d = -1; d <= ((int)TOTAL_ELEMENTS-2); d++) 

To forcibly convert TOTAL_ELEMENTS to int type, the result is changed:


.......... This is what we want, that is, the macro definition is okay.

Let's add a sentence in the original main () function.

int array_length = TOTAL_ELEMENTS;

In this way, the effect of type conversion should be the same. After tracking and monitoring, the following results are obtained:


The prompt is that the symbol "TOTAL_ELEMENTS" is not found, but the array_length has a value ....... Very depressing

Next, we process the array length in the for loop.

for(d = -1; d <= ((sizeof(array) / sizeof(array[0])) - 2); d++)

Now, the output result should be the array we want. But nothing is output ....... More depressing

Then continue tracking and monitoring.



It seems that there is no problem, but pay attention to their types. They are unsigned integers, while the circular condition d is an integer (int), and the initial value of d is-1, the value of unsigned int is no longer within the defined range. Now it seems to be a type problem. Let's change the initial value of circular condition d to 0:

#include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};
int main()
{
	int d;
	for(d = 0; d <= (TOTAL_ELEMENTS - 1); d++)
		printf("%d\n", array[d]);
	return 0;
}

The output result is


The result is exactly what we want. No forced type conversion or secondary value assignment is performed, but the initial value of circular condition d is defined within the unsigned int range.

Let's do another test.

int main ()
{
     int array [] = {23,34,12,17,204,99,16};
     int d = -1;
     if (d <= (sizeof (array) / sizeof (array [0])) -2)
         printf ("First chicken \ n");
     else
         printf ("An egg first \ n");
     return 0;
} 

From the code perspective, the output should be "first chicken ". However, this result is counterproductive, and the output is "first ".

Therefore, we recommend that you avoid using the unsigned type when writing code, and avoid comparing the signed type and the corresponding unsigned type.

========================================================== ======================================

I did not conduct any further research for any other reasons, but I only saw IT interview questions occasionally. I was interested in a simple test.

However, after tracking and monitoring, CX0017: error: the symbol "TOTAL_ELEMENTS" is not found, but the cause is still not found. If you have any knowledge, you may wish to give some advice ......


Interesting interview questions

There are three answers to this question:
RMB 1 and RMB 2 respectively earned RMB 2 for two times.
2, 3 yuan, this person initially spent 8 yuan, and finally took back 11 yuan, the difference between the two, for 3 yuan.
3.-2 RMB. The minimum purchase cost and maximum selling price of a person are 8 yuan and 11 yuan respectively. In the first transaction, this person sold at 9 yuan and lost 2 yuan, the second purchase was two yuan higher than the lowest cost, so there was a loss of two yuan, a total loss of 4 yuan. In the two transactions, he made a profit of 2 yuan, so he eventually lost 2 yuan.

Funny interview questions from well-known IT companies

1. Night is the shadow of the Earth.

2. The standard answer direction is to let the employees work for the weak, to win the customer's sympathy, and finally to get the computer back. Writing a letter is like writing an essay.

3. Assume that a person is a cuboid, the rain is evenly distributed, and the rain is vertical (no wind). The rain flies to people at a speed of 1 drop/second, then the concentration is 1 cm² 1 drop, while the shoulder width is 50 cm, the thickness is 10 cm, and the rain area is about 1 cm², and the thickness is about 0.1mm.
5*60*500*1*1*0.01*1g = 1500g.

4. Induction
1. One sick dog
After observing all the other dogs, the master of the sick dog finds that the other dogs are in the same State, so it must have been his dog, so he SHOT his dog on the first day.
2. Two sick dogs
On the first day, the dog owner finds that one of all other dogs is ill. There are two possibilities: Your dog is ill or you are not ill. If you are not ill, the dog will turn up that night, but the dog is still healthy the next day. So your dog is also a sick dog. Take a gun.
3. 3 sick dogs
Similarly, the dog owner saw two sick dogs outside. In order to determine the status of his dog, if the two were killed only on the evening of the seventh day, they would certainly be okay, if you do not hear any activity on the evening of 2nd, kill and kill
4, the same way, the dog owner saw a N-1 dog out there is a problem, will wait for the N-1 day, In the N-1 day night if did not hear dynamic and static, then his dog is the N sick dog, on the nth Day, the attacker shot the gun.
There should also be restrictions on this question, that is, the first is to be sure that there are diseased dogs in it, and the second is not all dogs are ill.

5. It should be a matter of series. The three colors are casual and each person has a good reputation.
Method: select one of the three colors on the first side and one of the three colors on the second side ...... Therefore, there are a total of three types: the power of 3, the power of 20, minus 3 (3 pure colors ).
Only two colors can be removed:
2 to the power of 20 minus 2 (2 pure colors) multiplied by 3 (two colors of the color scheme has 3 ).
Result:
3486784398-3145722 = 3483638676 types.

6, | A-B | = 21 A-B = 20
Equivalent
B-A = 21 A-B = 20
This question is theoretically unknown.

7. There is no way to get the biggest diamond. There is no solution to the problem. You can only say how to get the largest diamond as much as possible. This method is:
Choose not to take the first five floors, observe the diamond size of each layer, and be sure to know. Select the next five floors, and select the diamond with the largest diamond size near the first five floors.

The above is my answer. Hope someone is better than me.

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.