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
Answers were Sorted based on User's Feedback
Answer / 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 |
What are global variables and explain how do you declare them?
What is the difference between call by value and call by reference in c?
What does != Mean in c?
what are the 10 different models of writing an addition program in C language?
In the below code, how do you modify the value 'a' and print in the function. You'll be allowed to add code only inside the called function. main() { int a=5; function(); // no parameters should be passed } function() { /* add code here to modify the value of and print here */ }
write a function for strtok()??
Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?
whether itis a structured language?
write a program to fined second smallest and largest element in a given series of elements (without sorting)
Describe the modifier in c?
which one of follwoing will read a character from keyboard and store in c a)c=getc() b)c=getchar() c)c=getchar(stdin) d)getc(&c) e)none
How would you rename a function in C?