Output pridiction

A

Anshum Kocher

#include<stdio.h>

int &abc();
int main()
{

int b=abc();


getch();
return 0;
}
int &abc()
{
int a=5;
return a;
}


whats the output and why?
 
K

Kevin McCarty

#include<stdio.h>

int &abc();
int main()
{

  int b=abc();

   getch();
   return 0;}

int &abc()
{
    int a=5;
    return a;

}

whats the output and why?


This looks like homework...

Did you try compiling it with any decent compiler? Take a look at
what the warning messages tell you (leaving aside the fact that you
didn't put any #include in that would have defined "getch()")


~/tmp % g++ -Wall x.cpp
x.cpp: In function ‘int main()’:
x.cpp:9: error: ‘getch’ was not declared in this scope
x.cpp:7: warning: unused variable ‘b’
x.cpp: In function ‘int& abc()’:
x.cpp:15: warning: reference to local variable ‘a’ returned


T:\tmp> cl.exe /EHsc x.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 15.00.30729.01 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

x.cpp
x.cpp(9) : error C3861: 'getch': identifier not found
x.cpp(16) : warning C4172: returning address of local variable or
temporary


- Kevin B. McCarty
 
Y

yongjie

#include<stdio.h>

int &abc();
int main()
{

  int b=abc();

   getch();
   return 0;}

int &abc()
{
    int a=5;
    return a;

}

whats the output and why?

u r returning a reference to a local value.
 
N

Nick Keighley

#include<stdio.h>

int &abc();
int main()
{

  int b=abc();

   getch();
   return 0;}

int &abc()
{
    int a=5;
    return a;

}

whats the output and why?

a suffusion of yellow, because one hand clapping sounds like that
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top