InternDoor

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.

Practise them as a timed round9 roles open at HARMAN India

C and C++ 3

  1. C and C++Medium

    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;
    }
    1. 101 101 200
    2. 100 200 200
    3. 101 101 101
    4. 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.

  2. C and C++Medium

    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. 1
    2. 3
    3. 4
    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.

  3. C and C++Easy

    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 << ' ';
    }
    1. G F G
    2. F G
    3. G F
    4. 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

  1. Operating systemsMedium

    Each line of employee.txt reads like "ajay manager account 45000". Which command prints only the lines whose second field is manager?

    1. grep manager employee.txt
    2. awk '$2 == "manager"' employee.txt
    3. sort -k2 employee.txt
    4. 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.

  2. Operating systemsMedium

    Which command removes duplicate lines from a file while keeping the first copy of each in its original order?

    1. uniq file.txt
    2. awk '!seen[$0]++' file.txt
    3. sort file.txt
    4. 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.

Prep for other employers

All employers
See who is hiring after Harman

Engineering internships and entry-level jobs in India, newest first.