当前位置:网站首页>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边栏推荐
- 【Rust 笔记】13-迭代器(下)
- 阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
- Appium基础 — 使用Appium的第一个Demo
- Sum of three terms (construction)
- MySQL advanced part 2: MySQL architecture
- MySQL advanced part 2: SQL optimization
- 1040 Longest Symmetric String
- MySQL advanced part 1: View
- Leetcode-6109: number of people who know secrets
- Usage scenarios of golang context
猜你喜欢

WordPress switches the page, and the domain name changes back to the IP address

SQL三种连接:内连接、外连接、交叉连接

【LeetCode】Easy | 20. Valid parentheses

LeetCode-54

MySQL advanced part 2: SQL optimization

高斯消元 AcWing 884. 高斯消元解异或线性方程组

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

数据可视化图表总结(一)

Leetcode-6110: number of incremental paths in the grid graph

Redis publish subscribe command line implementation
随机推荐
Is it impossible for lamda to wake up?
redis发布订阅命令行实现
【Rust 笔记】14-集合(上)
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
Sqlmap tutorial (1)
1.15 - input and output system
[rust notes] 14 set (Part 1)
Groupbykey() and reducebykey() and combinebykey() in spark
SQL三种连接:内连接、外连接、交叉连接
[leetcode] day95 effective Sudoku & matrix zeroing
Leetcode-6110: number of incremental paths in the grid graph
Leetcode-3: Longest substring without repeated characters
leetcode-1200:最小绝对差
Daily question 1189 Maximum number of "balloons"
Leetcode divide and conquer / dichotomy
Usage scenarios of golang context
1041 Be Unique
MySQL advanced part 2: the use of indexes
MySQL advanced part 1: index
leetcode-3:无重复字符的最长子串