what is the output?
Answers were Sorted based on User's Feedback
Answer / prasad
it prints BYE on screen!!!
|Is This Answer Correct ?||6 Yes||0 No|
Answer / hussain reddy
|Is This Answer Correct ?||4 Yes||0 No|
Answer / deepa
SOORY FOR POSTIN THE WRONG ANSWER THE ANSER WUD BE BYE COZ
THE *P DIES IN THE FUNCTION ITSELF AS WE ARE NOT RETURNING
THE STRING BACK IN THE MAIN PROGRAM
|Is This Answer Correct ?||3 Yes||1 No|
Answer / vijay
The out put is "BYE".
Because the pointer p dies when function exit with out
return,in main pointer p points to only "BYE",so prinf
prints which p points in main.
|Is This Answer Correct ?||2 Yes||1 No|
Answer / smirnov_amm
It will show "HELL"
the f function reserve only 4 bytes with the sizeof(6). it will return the sizeof (int) =4 bytes.
So you only allocate 4 bytes.
When performing the strcpy, you will corupt memory because you'll copy more than allocate.
|Is This Answer Correct ?||0 Yes||0 No|
Answer / yathish m yadav
the output is "hello".
here we are overwriting pointer *p thrice.
that is in the function we get an piece of memory from
malloc and assigned to p,
in the statement strcpy(p,"hello");
the malloc memory is lost and the compiler creates an char
array and copies the string "hello" and it makes the
character array as constant.
|Is This Answer Correct ?||0 Yes||2 No|
Answer / deepa
the outpu is hello coz the pointer is pointing to a
location where the string "bye" is written in the next
program yu are using the same pointer to point to some
other string so it gets overwritten
|Is This Answer Correct ?||2 Yes||5 No|
Answer / anu
the output wll be hello , since the argument is overwritten
with new memory in the function.
so in main, when it comes to printf, p points to the
allocatd memory, which contains hello
|Is This Answer Correct ?||0 Yes||3 No|
The output would be "HELLO"..
though we are not returning the string, we are making
direct changes at the memory location..
so "bye" will be overwritten with "HELLO"
because we are using pointers, the dying pointer scenario
is not applicabe here..
Its a pointer, not a variable..
This function will work similar to -> swapping two numbers
juss check that prog if you fnd somewhere.. :-)
you will get the logic... :-)
--By the way a gud ques.. :-)
|Is This Answer Correct ?||0 Yes||4 No|
difference between memcpy and strcpy
Can U write a C-program to print the size of a data type without using the sizeof() operator? Explain how it works inside ?
how to get starting address of a running C program
what's the return value of malloc()
Binary tree traversing
4) Write a program that takes a 5 digit number and calculates 2 power that number and prints it. i have done maximum par but i m findind problem in the commented area. please help...
How to use c/c++ code in JAVA
Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?
how to reverse string "Hello World" by using pointers only. Without any temp var
i want to job in your company, so how it will be possible.
why Language C is plateform dependent
WHAT IS HEADER?