C++ Interview Question and Answers – Part 2

61. What are the two kinds of expressions in C ?
Answer : In C, the two type of expressions are lvalue and rvalue. An lvalue is something that identifies an object. This includes objects whose machine addresses may not be taken, such as bit-fields and register variables.ie, Expressions that refer to a memory location.An rvalue is the value of an expression. ie,refers to a data value that is stored at some address in memory Variables are lvalues and may appear on the left-hand side of an assignment. Numeric literals are rvalues and cannot appear on the left-hand side.

62. Explain Character Constants vs String Literals ?
Answer : Character literals are those which is enclosed in single quotes, example., ‘a’ can be stored in a simple variable of char type. String literals are enclosed in double quotes “”.

63. What is a sequential access file?
Answer : When writing programs that will store and retrieve data in a file, it is possible to designate that file into different forms. A sequential access file is such that data are saved in sequential order: one data is placed into the file after another. To access a particular data within the sequential access file, data has to be read one data at a time, until the right one is reached.

64. How do you declare a variable that will hold string values?
Answer : The char keyword can only hold 1 character value at a time. By creating an array of characters, you can store string values in it. Example: “char MyName[50]; ” declares a string variable named MyName that can hold a maximum of 50 characters.

65. Can the curly brackets { } be used to enclose a single line of code?
Answer : While curly brackets are mainly used to group several lines of codes, it will still work without error if you used it for a single line. Some programmers prefer this method as a way of organizing codes to make it look clearer, especially in conditional statements.

Leave a Reply

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