- Printf can be implemented by using __________ list.
Answer:
Variable length argument lists
- char *someFun(){
char *temp = “string constant";
return temp;
}
int main(){
puts(someFun());
}
Answer:
string constant
Explanation:
The program suffers no problem and gives the output correctly because the character constants are stored in code/data area and not allocated in stack, so this doesn’t lead to dangling pointers.
- char *someFun1(){
char temp[ ] = “string";
return temp;
}
char *someFun2(){
char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’};
return temp;
}
int main(){
puts(someFun1());
puts(someFun2());
}
Answer:
Garbage values.
Explanation:
Both the functions suffer from the problem of dangling pointers. In someFun1() temp is a character array and so the space for it is allocated in heap and is initialized with character string “string”. This is created dynamically as the function is called, so is also deleted dynamically on exiting the function so the string data is not available in the calling function main() leading to print some garbage values. The function someFun2() also suffers from the same problem but the problem can be easily identified in this case.
- Explain Internal linkage.
Internal linkage means that all declarations of the identifier within one source file refer to a single entity but declarations of the same identifier in other source files refer to different entities.
- Can the formal parameter to a function be declared static?
No, because arguments are always passed on the stack to support recursion.
- What is an lvalue?
Something that can appear on the left side of the "=" sign, it identifies a place where the result can be stored. For example, in the equation a=b+25, a is an lvalue.
In the equation b+25=a, b+25 cannot be used as an lvalue, because it does not identify a specific place. Hence the above assignment is illegal.
- Every expression that is an lvalue, is also an rvalue. Is the reverse true?
No, lvalue denotes a place in the computer's memory. An rvalue denotes a value, so it can only be used on the right hand side of an assignment.
- What happens if indirection is performed on a NULL pointer?
On some machines the indirection accesses the memory location zero. On other machines indirection on a NULL pointer cause a fault that terminate the program. Hence the result is implementation dependent.
- Is the statement legal? d=10-*d.
Illegal because it specifies that an integer quantity (10-*d) be stored in a pointer variable
- What does the below indicate?
int *func(void)
- void indicates that there aren't any arguments.
- there is one argument of type void.
Answer: a
No comments:
Post a Comment