473,320 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Re: output of program

On Apr 11, 12:06 pm, Rahul <sam_...@yahoo.co.inwrote:
Hi Everyone,

I have the following program,

class A{
private:
int a;
public :
void func1();

};

void A::func1(){
cout <<"hello world";

}

int main(){
A *a1=NULL;
a1->func1();
return 0;

}

And it prints hello world. I think it is undefined behavior but i'm
assuming that the memory for the function is allocated as the compiler
parses through the class definition and hence there should be a way to
access the memory (function)... Is there any legal way without
creating an object of the class?

Thanks in advance ! ! !
I am not sure, but compiler passes
func1(this);

In your case this == NULL. However since func1(...) is not accessing
'this', so things worked.
I do not think such type of code will work, if you are accessing class
bound memory.

With Regards,
Reetesh Mukul
Jun 27 '08 #1
0 1540

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Yuan HOng | last post by:
In my program I have to call an external program and parse its output. For that I use the os.popen2 function, and then read the output stream. But the complexity is that the external program...
0
by: Keith Dick | last post by:
I'm trying to use the free command line C/C++ compiler for .NET and when I try to debug a simple C program that uses printf(), I don't see the output it produces. A console window does open when...
54
by: bnp | last post by:
Hi, I took a test on C. there was an objective question for program output type. following is the program: main() { char ch; int i =2;
22
by: Jaspreet | last post by:
I was recently asked this question in an interview. Unfortunately I was not able to answer it and the interviewer made a decision on my C strengths (or weekness) based on this single question and...
3
by: Liren Zhao | last post by:
I use some "Console.WriteLine(some strings here)" to display some debug information in my winform program. How can I get the information in my programe or same them in a text file ?
2
by: JezB | last post by:
I'm compiling an old C program within Visual Studio to give me the advantages of debugging within this environment. I'm building it as a Console application using C++ as the language. It compiles...
1
by: noleander | last post by:
Hi. I've got a C++ program written in Visual C++ 2003. The program is trivial, created with the Program-creation wizard: used the .NET "Form" template. The program has a trivial...
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
0
by: jebbyleezer | last post by:
Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty. Here is my source code: import java.io.*; import java.util.Scanner;...
87
by: pereges | last post by:
I have a C program which I created on Windows machine. I have compiled and executed the program on windows machine and it gives me the consistent output every time i run it. for eg. input a = 2,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.