C++ Interview Question and Answers – Part 2

96. What is extern and static function in c?
Answer : By default, any function that is defined in a c file is extern. These functions can be used in any other source file of the same project which has many other files. When we declare/define a function as static, these functions can’t be used in other files of the same project. Also, if we want to use the same function name in different files of the same project, we can use static function which won’t through any compilation error for duplicate function name.

97. Is C language case sensitive?
Answer : Yes. C language instructions/commands/functions and everything used in C program are case sensitive.

98. How do you generate random numbers in C?
Answer : Random numbers are generated in C using the rand() command. For example: anyNum = rand() will generate any integer number beginning from 0, assuming that anyNum is a variable of type integer.

99. Differentiate between for loop and a while loop? What are it uses?
Answer : Ans: For executing a set of statements fixed number of times we use for loop while when the number of iterations to be performed is not known in advance we use while loop.

100. What is the difference between Strings and Arrays?
Answer : String is a sequence of characters ending with NULL .it can be treated as a one dimensional array of characters terminated by a NULL character.

Leave a Reply

Your email address will not be published. Required fields are marked *