Harman interview prep
5 practice questions on the topics candidates reported from Harman interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
C and C++ 3
-
What does this print?
#include <stdio.h> int main(void) { int a[5] = {100, 200, 300, 400, 500}; int *p = a; ++*p; printf("%d %d ", a[0], *p); p = a; *++p; printf("%d", *p); return 0; }- 101 101 200
- 100 200 200
- 101 101 101
- 100 101 300
Show the answer
A. 101 101 200
++*p increments the value p points at, so a[0] becomes 101. *++p moves the pointer first, to a[1], then reads it (the read is unused), so *p is 200.
This topic is named in a candidate’s interview report: C developer interview, Bengaluru, 2023, on LeetCode.
-
What does this print?
#include <stdio.h> #include <string.h> int main(void) { char s[] = "77.6;1778;NA;43"; int n = 0; for (char *t = strtok(s, ";"); t; t = strtok(NULL, ";")) n++; printf("%d", n); return 0; }- 1
- 3
- 4
- 15
Show the answer
C. 4
strtok splits on ";" and returns one token per call: 77.6, 1778, NA and 43. It writes a \0 into the string at each delimiter, so it needs a writable array, not a string literal.
This topic is named in a candidate’s interview report: C developer interview, Bengaluru, 2023, on LeetCode.
-
What does this print?
#include <iostream> #include <set> int main() { std::set<char> a; a.insert('G'); a.insert('F'); a.insert('G'); for (char c : a) std::cout << c << ' '; }- G F G
- F G
- G F
- F G G
Show the answer
B. F G
std::set keeps unique elements in sorted order, so the second G is ignored and F comes before G. std::multiset would keep both Gs; std::unordered_set has no defined order.
This topic is named in a candidate’s interview report: C developer interview, Bengaluru, 2023, on LeetCode.
Operating systems 2
-
Each line of employee.txt reads like "ajay manager account 45000". Which command prints only the lines whose second field is manager?
- grep manager employee.txt
- awk '$2 == "manager"' employee.txt
- sort -k2 employee.txt
- cut -d' ' -f2 employee.txt
Show the answer
B. awk '$2 == "manager"' employee.txt
awk splits each line into fields $1, $2, ... and prints the lines where the condition holds. grep would also match manager anywhere else in a line; cut prints only the field itself.
This topic is named in a candidate’s interview report: C developer interview, Bengaluru, 2023, on LeetCode.
-
Which command removes duplicate lines from a file while keeping the first copy of each in its original order?
- uniq file.txt
- awk '!seen[$0]++' file.txt
- sort file.txt
- wc -l file.txt
Show the answer
B. awk '!seen[$0]++' file.txt
seen[$0]++ is 0 the first time a line appears, so !0 prints it, and every later copy is skipped. uniq only removes adjacent duplicates, and sort -u removes them but changes the order.
This topic is named in a candidate’s interview report: C developer interview, Bengaluru, 2023, on LeetCode.