当前位置:网站首页>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边栏推荐
- Daily question 1189 Maximum number of "balloons"
- Leetcode-6108: decrypt messages
- Open source storage is so popular, why do we insist on self-development?
- QQ computer version cancels escape character input expression
- LeetCode 0107.二叉树的层序遍历II - 另一种方法
- [2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
- 4. 对象映射 - Mapping.Mapster
- Leetcode dynamic programming
- MySQL advanced part 2: optimizing SQL steps
- Real time clock (RTC)
猜你喜欢
Appium foundation - use the first demo of appium
MySQL advanced part 2: the use of indexes
MySQL advanced part 1: index
LaMDA 不可能觉醒吗?
Open source storage is so popular, why do we insist on self-development?
Sqlmap tutorial (1)
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
LeetCode-61
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
Redis publish subscribe command line implementation
随机推荐
MySQL advanced part 2: the use of indexes
4. 对象映射 - Mapping.Mapster
【Rust 笔记】14-集合(下)
Appium基础 — 使用Appium的第一个Demo
MySQL advanced part 1: View
Nested method, calculation attribute is not applicable, use methods
数据可视化图表总结(一)
1041 Be Unique
4. Object mapping Mapster
1041 Be Unique
【Rust 笔记】15-字符串与文本(上)
[BMZCTF-pwn] ectf-2014 seddit
LeetCode 1200. Minimum absolute difference
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
11-gorm-v2-02-create data
JS quickly converts JSON data into URL parameters
Groupbykey() and reducebykey() and combinebykey() in spark
WordPress switches the page, and the domain name changes back to the IP address
LeetCode 0108.将有序数组转换为二叉搜索树 - 数组中值为根,中值左右分别为左右子树
LeetCode 0107.二叉树的层序遍历II - 另一种方法