What will be result of the following program?
void myalloc(char *x, int n)
{
x= (char *)malloc(n*sizeof(char));
memset(x,\0,n*sizeof(char));
}
main()
{
char *g="String";
myalloc(g,20);
strcpy(g,"Oldstring");
printf("The string is %s",g);
}
a) The string is : String
b) Run time error/Core dump
c) The string is : Oldstring
d) Syntax error during compilation
e) None of these
Answer Posted / rishabh taneja
correct the line: memset(x,\0,n*sizeof(char)); as
memset(x,'\0',n*sizeof(char));
Result(if the line mentioned is corrected):
The string is: Oldstring
The result is verified by me by actually running it.
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Which header file is essential for using strcmp function?
What are the advantages of the functions?
"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks
Differentiate between null and void pointers.
What is void main ()?
What are identifiers c?
An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode
Is it better to use malloc() or calloc()?
List out few of the applications that make use of Multilinked Structures?
What are the types of assignment statements?
What do you mean by a sequential access file?
What is the value of uninitialized variable in c?
How can I do peek and poke in c?
What is wrong in this statement? scanf(ā%dā,whatnumber);
What is struct node in c?