num=100
sum=0.0123456789
text="C++ Fun"
print "Integer variable starts at",hex(id(num))
print "Double variable starts at",hex(id(sum))
print "String variable starts at",hex(id(text))
a=8
b=16
aPtr=id(a)
bPtr=id(b)
print "Address of pointers..."
print "aPtr:",hex(id(aPtr))
print "bPtr:",hex(id(bPtr))
print "Values in pointers..."
print "aPtr:",hex(aPtr)
print "bPtr:",hex(bPtr)
#As python does not support pointers values can't be displayed using * symbol
nums={1,2,3,4,5,6,7,8,9,10}
ptr=id(nums)
#As python does not support concept of pointers we can not use pointer arithmetic to print numbers
num=5
def writeOutput(value):
print "Current Value: ",value
def computeTriple(value):
global num
num=num*3
writeOutput(num)
num=num+15
writeOutput(num)
computeTriple(num)
writeOutput(num)
letters=['C','+','+',' ','F','u','n','\0']
text="C++ Fun"
term="Element"
lang="C++"
ap1=["Great ","Program ","Code "]
ap2=[lang,"is ","Fun"]
ap3=[ap2[0],ap2[1],ap1[0]]
ap4=[ap1[2],ap2[1],ap2[2]]
print "".join(letters)
print text
for i in range(0,3):
print term,i," ",
print ap1[i]," ",
print ap2[i]," ",
print ap3[i]," ",
print ap4[i]," "
num=0
rNum=400
num=rNum
print "Value direct",num
print "Value via reference ",rNum
print "Address direct",hex(id(num))
print "Address via reference",hex(id(rNum))
rNum=rNum*2
num=rNum
print "Value direct",num
print "Value via reference ",rNum
#as python does not support pointers
def writeOutput(value):
print "Current Value: ",value
def computeTriple(value):
value=value*3
print "Current Value: ",value
num=5
ref=num
writeOutput(num)
num=num+15
writeOutput(num)
computeTriple(num)
#as python does not support pointers I dont have used pointer in this program
def add(a,b):
total=a+b
print "total:",total
num=100
sum=500
rNum=num
ptr=num
print "Reference:",rNum
print "Pointer:",ptr
ptr=sum
print "Pointer now:",ptr
add(rNum,ptr)
#as python does not support pointers I dont have used pointer in this progaram