Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


what would be the output of the following program?
main()
{
int k = 123;
char *ptr;
ptr = &k;
printf("%d",*ptr);
}

Answers were Sorted based on User's Feedback



what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &..

Answer / vadivelt

Output would be 123.

Since, the character pointer can hold the values
0 - 255(if it is unsigned) or -128 to 127 (if it is signed), we
will get value of k as result.

But if the k value is k > 255 and the pointer is unsigned,
or if the k value is k > -129 and k < 128 and the pointer
is signed then only lower 1 byte of k would be the result.
Remaining data will be lost.

Is This Answer Correct ?    4 Yes 0 No

what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &..

Answer / vadivelt

Hi Srsabariselvan,
If you are not very clear on the answer, please avoid to post
it. Because your answer seems to be misguiding the persons
who are very new to this question(probly pointers).

Who said that a pointer has to hold the address of same
datatype????.... a pointer of any datatype can hold the
address of any other data types(only it is enough to have
proper typecasting).

There will not be a compilation error. But most of the time
loss of data may be there(ie., when a bigger size of
datatype is typecasted to smaller eg: int* is typecasted to
char*). Please read the answer #1 for clear understanding.

Still if you are not clear on the concept, Copy the code
and execute it in ur compiler and analys the output.

Is This Answer Correct ?    2 Yes 1 No

what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &..

Answer / srsabariselvan

The program results in compilation error.

NOTE: a pointer can stores the address of same data type.
it can't store the address of another data type.
i.e.,
character pointer can stores the address of character data.
it can't store the address of integer data.

Is This Answer Correct ?    2 Yes 2 No

what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &..

Answer / ankush

i also have a compilation error.....
""Cannot convert 'int_ss*' to 'char*' in function main()""
why its so....???
i want some answer.....
is my compiler wrong....

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Why & is used in scanf in c?

0 Answers  


What is wrong in this statement?

0 Answers  


Create a structure to specify data on students as given below: Roll number, Name, Department, Course, and Year of joining. Assume that there are not more than 450 students in the collage. (a) Write a function to print the names of all students who joined in the last 3 years. (b) Write a function to print the data of a student whose roll numbers are divisible by 4.

0 Answers  


what is software?

7 Answers   Wipro,


What is a pointer and how it is initialized?

0 Answers  


write a C program, given number is double without using addt ion and multiplication operator?ex:n=6,ans=12,pls send me ans to goviseenu@gmail.com

6 Answers  


Explain Basic concepts of C language?

0 Answers   EXL,


write a program that print itself even if the source file is deleted?

2 Answers  


What is the output of following program ? int main() { int x = 5; printf("%d %d %d\n", x, x << 2, x >> 2); }

5 Answers   Amazon, Qualcomm,


main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); }

10 Answers   TCS, Vector,


how many key words availabel in c a) 28 b) 31 c) 32

0 Answers  


write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3

0 Answers   ADP,


Categories