当前位置:网站首页>C job interview - casting and comparing - C job interview - casting and comparing
C job interview - casting and comparing - C job interview - casting and comparing
2022-07-05 06:18:00 【Technology feast】
problem :
I was confronted with a tricky (IMO) question. I encountered a difficult problem (IMO) problem .I needed to compare two MAC addresses , in the most efficient manner. I need to compare the two in the most effective way MAC Address .
The only thought that crossed my mind in that moment was the trivial solution - a for loop, and comparing locations, and so I did, but the interviewer was aiming to casting. At that moment , The only thing I can think of is a trivial solution —— One for loop , Compare positions , So I did , But the interviewer's goal is to cast .
The MAC definition:MAC Definition :
typedef struct macA { char data[6];} MAC;And the function is (the one I was asked to implement): The function is ( What I was asked to do ):
int isEqual(MAC* addr1, MAC* addr2){ int i; for(i = 0; i<6; i++) { if(addr1->data[i] != addr2->data[i]) return 0; } return 1;}But as mentioned, he was aiming for casting. But as mentioned before , His goal is to cast .
Meaning, to somehow cast the MAC address given to an int, compare both of the addresses, and return. intend , In some way, the given MAC Address conversion to int, Compare two addresses , Then return .
But when casting, int int_addr1 = (int)addr1; But when converting , int int_addr1 = (int)addr1;, only four bytes will be casted, right?, Only four bytes will be projected , Am I right? ?Should I check the remaining ones? Should I check the rest ?Meaning locations 4 and 5? It means location 4 and 5?
Both char and int are integer types so casting is legal, but what happens in the described situation?char and int They're all integer types , Therefore, coercion is legal , But what happens in the described situation ?
Solution :
Reference resources : https://stackoom.com/en/question/1PWLU边栏推荐
- A reason that is easy to be ignored when the printer is offline
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- Simple selection sort of selection sort
- Data visualization chart summary (I)
- Nested method, calculation attribute is not applicable, use methods
- SQLMAP使用教程(二)实战技巧一
- MIT-6874-Deep Learning in the Life Sciences Week 7
- [rust notes] 16 input and output (Part 2)
- LeetCode 1200.最小绝对差
- Spark中groupByKey() 和 reduceByKey() 和combineByKey()
猜你喜欢

实时时钟 (RTC)

Arduino 控制的 RGB LED 无限镜

NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar

做 SQL 性能优化真是让人干瞪眼

【LeetCode】Easy | 20. Valid parentheses

LVS简介【暂未完成(半成品)】

什么是套接字?Socket基本介绍

博弈论 AcWing 894. 拆分-Nim游戏

LeetCode 0107. Sequence traversal of binary tree II - another method

WordPress switches the page, and the domain name changes back to the IP address
随机推荐
Groupbykey() and reducebykey() and combinebykey() in spark
【Rust 笔记】14-集合(下)
[rust notes] 17 concurrent (Part 2)
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
Operator priority, one catch, no doubt
Sqlmap tutorial (II) practical skills I
【Rust 笔记】16-输入与输出(上)
MySQL advanced part 1: View
LeetCode-54
1039 Course List for Student
11-gorm-v2-03-basic query
阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长
Basic explanation of typescript
开源存储这么香,为何我们还要坚持自研?
Sum of three terms (construction)
1040 Longest Symmetric String
Règlement sur la sécurité des réseaux dans les écoles professionnelles secondaires du concours de compétences des écoles professionnelles de la province de Guizhou en 2022
Presentation of attribute value of an item
Leetcode recursion
4. 对象映射 - Mapping.Mapster