Visit Our UNIX and Linux User Community


NULL printing a value 0xbf940000 and not a zero


 
Thread Tools Search this Thread
Top Forums Programming NULL printing a value 0xbf940000 and not a zero
# 1  
Old 08-27-2013
NULL printing a value 0xbf940000 and not a zero

hello all,
in the following code a -> next should print zero, but it is giving the output as 0xbf940000

Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Node
{
   public:
   int data;
   Node *next;
   Node(int n=1)
   {
    data=10;
    next=0;
   }
};
void main()
{
 Node *a;
 clrscr();
 a=new Node();
 cout<<a->data<<endl;
 cout<<a->next<<endl;
 getch();
}

Moderator's Comments:
Mod Comment Please use code tags and not icode

Last edited by Corona688; 08-27-2013 at 01:22 PM..
# 2  
Old 08-27-2013
Try passing a number into the constructor, by not giving it a number you may be telling it not to use your own constructor but a do-nothing default constructor..

You should always write a default constructor, since it's used in a surprising number of situations.

Last edited by Corona688; 08-27-2013 at 01:52 PM..
# 3  
Old 09-08-2013
i string with printf instead of cout and i got 0
# 4  
Old 09-09-2013
I am not sure which platform or compiler you are using. The use of <iostream.h>, <conio.h>, void main(), etc. would suggest you are on a Windows platform.

The following gives the expected output on modern Linux platforms:
Code:
#include <iostream>

using namespace std;

class Node
{
   public:
   int data;
   Node *next;

   Node()
   {
       data=10;
       next=0;
   }
};

int main()
{
   Node *a;
   a = new Node();

   cout << a->data << endl;
   cout << a->next << endl;

   return 0;
}


Previous Thread | Next Thread
Test Your Knowledge in Computers #390
Difficulty: Medium
SdlBasic is a multiplatform interpreter for BASIC which can be used to make games in 2d style amos for linux and windows.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printing, SYSPRINTER, IP printing

Dear readers, We have a printer problem with a UNIX system. The OS is Unix IRIX 6.5 We have connected a printerto the system. If we then make a test print everything goes well . (IP printing) But if we make a print from the "orrga,i"program. Then we see all the printouts stuck within the... (3 Replies)
Discussion started by: SergevdH
3 Replies

2. Shell Programming and Scripting

Printing null values in awk

Hi, I have a csv file with given details abc.txt 123,ra,point,,there 232,ba,points,home,pheer I want to get those values and store them in different variables: Code: while read line do echo $line |awk -F"," '{print $1" "$2" "$3" "$4" "$5"}'|read dbt_acct val_dt crncy AMT... (11 Replies)
Discussion started by: rahulsk
11 Replies

3. Shell Programming and Scripting

Perl: Printing null hash values as a " "?

I'm filling in a table of values for grades. I decided to go with reading into a hash from the files but I'm coming up with an error when printing a value that does not exist. I need to know if I can on-the-fly print a space (" ") or blank in place of the grade. Here's what the output should... (2 Replies)
Discussion started by: D2K
2 Replies

4. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

5. UNIX for Dummies Questions & Answers

Sco Unix printing : jobs hangs in queue - printing via lp versus hpnpf

Hi, We have a Unix 3.2v5.0.5. I installed a printer via scoadmin, HP network printer manager with network peripheral name (hostname and ipadres are in /etc/hosts). This is the configuration file : Code: root@sco1 # cat configurationBanner: on:AlwaysContent types: simpleDevice:... (0 Replies)
Discussion started by: haezeban
0 Replies

6. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

7. UNIX for Dummies Questions & Answers

/dev/null 2>&1 Versus /dev/null 2>1

How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&" echo "hello" > /dev/null 2>&1 echo "hello" > /dev/null 2>1 (3 Replies)
Discussion started by: glev2005
3 Replies

8. Shell Programming and Scripting

Insert string 'NULL' where there is a null value

I have an input file having 7 fields delimited by , eg : 1,ABC,hg,1,2,34,3 2,hj,YU,2,3,4, 3,JU,kl,4,5,7, 4,JK,KJ,3,56,4,5 The seventh field here in some lines is empty, whereas the other lines there is a value. How do I insert string NULL at this location (7th loc) for these lines where... (8 Replies)
Discussion started by: zilch
8 Replies

9. Shell Programming and Scripting

compare null with non-null

I've got a very peculiar situation. I'm trying to find out if we can compare null fields with non-null. I've output csv files from SQL and Oracle. I need to compare each field from the files, and then find out any differences. The files usualy have over 500 fields, and send the resule to DBA.... (8 Replies)
Discussion started by: nitin
8 Replies

10. UNIX for Advanced & Expert Users

Printing Problems in unix ... ( Bar-cdoe - Ip Printing)

Hi guys ... i need ur help with some printing problem in unix ... first prob. : i wanna print from my NCR unix to an Win NT , Ip based printing server ( HP JetDirect ) . My issue , is it possible to print directly to an Ip address from unix ? How do i make it work to get any results ?... (3 Replies)
Discussion started by: QuickSilver
3 Replies

Featured Tech Videos