# There is no concept of pointer in pyton and this program is based on pointer so i have done in this manner
ptr_ch=chr
ptr_int=int
ptr_db=float
#Char pointer ptr_ch
print " Corrent position of ptr_ch: %#x " % id(ptr_ch)
print " The position after ptr_ch+1 : %#x" % (id(ptr_ch)+1)
print " The position after ptr_ch+2 : %#x" % (id(ptr_ch)+2)
print " The position after ptr_ch+1 : %#x" % (id(ptr_ch)+1)
print " The position after ptr_ch+2 : %#x\n" % (id(ptr_ch)+2)
print " Corrent position of ptr_int: %#x " % id(ptr_int)
print " The position after ptr_int+1 : %#x" % (id(ptr_int)+1)
print " The position after ptr_int+2 : %#x" % (id(ptr_int)+2)
print " The position after ptr_int+1 : %#x" % (id(ptr_int)+1)
print " The position after ptr_int+2 : %#x\n" % (id(ptr_int)+2)
print " Corrent position of ptr_db: %#x " % id(ptr_db)
print " The position after ptr_db+1 : %#x" % (id(ptr_db)+1)
print " The position after ptr_db+2 : %#x" % (id(ptr_db)+2)
print " The position after ptr_db+1 : %#x" % (id(ptr_db)+1)
print " The position after ptr_db+2 : %#x\n" % (id(ptr_db)+2)
# There is no concept of pointer in pyton and this program is based on pointer so i have done in this manner
ptr_int1=int
ptr_int2=int
print "The position of ptr_int1: %#x" % id(ptr_int1)
ptr_int2=id(ptr_int1)+5
print "The position of ptr_int2=id(ptr_int1)+5 :%#x" % ptr_int2
print "The subtraction of ptr_int2-ptr_int1 :%#x" % (ptr_int2 - id(ptr_int1))
ptr_int2=id(ptr_int1)-5
print "The position of ptr_int2=id(ptr_int1)-5 :%#x" % ptr_int2
print "The subtraction of ptr_int2-ptr_int1 :%#x" % (ptr_int2 - id(ptr_int1))
# There is no concept of pointer in pyton and this program is based on pointer so i have done in this manner
str1="It's a string!"
ptr_str=chr
list1=[1,2,3,4,5]
ptr_int=int
str1=list(str1)
ptr_str=str1
print "Before the change, str1 contains: ",
print "".join(str1)
print "Before the change, str1[5] contains : %c" % str1[5]
str1[5]='A'
print "After The change, str1[5] contains : %c" % str1[5]
print "After The change, str1 contains: ",
print "".join(str1)
ptr_int=list1
print "Before The change, list1[2] contains: %d" % list1[2]
list1[2]=-3
print "After the change, list1[2] contains : %d" % list1[2]
def AddThree(list1):
result=0
for i in range(len(list1)):
result=result+list1[i]
return result
sum1=0
listt=[x for x in range(3)]
listt[0]=int(raw_input("Enter integer1 :"))
listt[1]=int(raw_input("Enter integer2 :"))
listt[2]=int(raw_input("Enter integer3 :"))
sum1=AddThree(listt)
print "The sum of three integers is: %d" % sum1
# There is no concept of pointer in pyton and this program is based on pointer so i have done in this manner
def ChPrint(c):
print "%s" % c
def DataAdd(list1,max1):
sum1=0
for i in range(max1):
sum1 += list1[i]
return sum1
str1="It's a string!"
ptr_str=chr
listt=[1,2,3,4,5]
ptr_int=int
ptr_str=str1
ChPrint(ptr_str)
ChPrint(str1)
ptr_int=listt
print "The sum returned by DataAdd() : %d" % DataAdd(ptr_int,5)
print "The sum returned by DataAdd() : %d" % DataAdd(listt,5)
# There is no concept of pointer in pyton and this program is based on pointer so i have done in this manner
def DataAdd(list1,max1,max2):
sum1=0
for i in range(max1):
for j in range(max2):
sum1 = sum1 + list1[i][j]
return sum1
def DataAdd2(list2,max1,max2):
sum2=0
for i in range(max1):
for j in range(max2):
sum2 = sum2 + list2[i][j]
return sum2
listt=[[1,2],[3,4],[5,5],[4,3],[2,1]]
ptr_int=int
print "The sum returned by DataAdd() : %d" % DataAdd(listt,5,2)
ptr_int=listt
print "The sum returned by DataAdd() : %d" % DataAdd2(ptr_int,5,2)
def StrPrint1(str1,size):
for i in range(size):
print "%s" % str1[i]
def StrPrint2(str2):
print "%s" % str2
str1=["There's music in the sighing of a reed;","There's music in the gushing of a rill;","There's music in all things if men had ears;","There earth is but an echo of the spheres.\n"]
size=4
StrPrint1(str1,size)
for i in range(size):
StrPrint2(str1[i])
# There is no concept of pointer in pyton and this program is based on pointer so i have done in this manner
def StrPrint(str1):
print "%s" % str1
str1="Pointing to a function"
ptr=StrPrint
if(not(ptr(str1))):
print "Done."