当前位置:网站首页>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边栏推荐
- How to generate an image from text on fly at runtime
- MySQL advanced part 1: View
- 打印机脱机时一种容易被忽略的原因
- 1.14 - assembly line
- leetcode-1200:最小绝对差
- How to understand the definition of sequence limit?
- Redis publish subscribe command line implementation
- Open source storage is so popular, why do we insist on self-development?
- Usage scenarios of golang context
- Golang uses context gracefully
猜你喜欢
随机推荐
Leetcode-556: the next larger element III
MySQL advanced part 1: index
Presentation of attribute value of an item
[rust notes] 15 string and text (Part 1)
【Rust 笔记】16-输入与输出(下)
WordPress switches the page, and the domain name changes back to the IP address
SQLMAP使用教程(一)
SQLMAP使用教程(二)实战技巧一
Open source storage is so popular, why do we insist on self-development?
【Rust 笔记】14-集合(下)
Single chip computer engineering experience - layered idea
Leetcode divide and conquer / dichotomy
MySQL advanced part 1: triggers
Appium foundation - use the first demo of appium
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
[BMZCTF-pwn] ectf-2014 seddit
leetcode-9:回文数
Multi screen computer screenshots will cut off multiple screens, not only the current screen
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