'''
python does not have pointer functionality.We can get it explicitly.
'''
class ref:
def __init__(self, obj): self.obj = obj
def get(self): return str(self.obj)
def set(self, obj): self.obj = obj
x=ref([0])
p=x # assigning variable value to p
p.set(0) # set x to zero */
print "\nx is " + x.get()
print "\np is " + p.get()
a = p.get()
p.set(int(a)+1) # increment what p points to */
print "\nx is " +x.get()
a = p.get()
p.set(int(a)+1) # increment what p points to */
print "\nx is " + x.get()
def date(a,b): # /* declare the function */
day_ret =0
month_ret = 0
''' At this point, calculate the day and month
* values in day_ret and month_ret respectively.
'''
a = day_ret;
b = month_ret;
return a,b
month = 5
day = 1
d,m = date(day,month);
print "day is %d, month is %d\n" %(d, m)
from array import array
ARSZ=20
ar=[]
for i in range(ARSZ + 1):
ar.append( i)
print "ar[%d] now = %d\n" %( i, ar[i])
ARSZ = 10
fp1= ARSZ
fp2=0
while(fp2 != fp1):
print "Difference: %d\n" %((ARSZ-fp1))
fp1 -= 1
s = raw_input("Enter String:")
print len(s)
def str_eq(s1,s2):
if s1==s2:
return True
return False
print str_eq("this","hello")
print str_eq("this","this")
cp = "a string";
for i in cp:
print i,
print "\n"
for i in range(len(cp)):
print cp[i],
import numpy
ARLEN=10
ar = numpy.zeros(ARLEN)
print ar
'''
Python does not have any concept of pointer.
Python will go same for all mentioned.
'''
MAXSTRING=50 # /* max no. of strings */
MAXLEN = 80 #/* max length. of strings */
strings = [] # list of strings
def print_arr(a):
print a
def sort_arr(a):
a.sort()
return a
def next_string():
s = raw_input("Enter Next String : ")
strings.append(s)
return s
nstrings = 0
while(nstrings < MAXSTRING and next_string() != '0'):
nstrings += 1
print_arr(strings)
print sort_arr(strings)
'''
We need not to worry about memory allocation and deallocation in python.
It is simple to get a string, print and copy it.
'''
str_p = ""
tmp_p = ""
str_p = raw_input("Enter String.. : ")
next_p = str_p
chars_read = len(str_p)
tmp_p = str_p
print tmp_p
print str_p
arr = "hello"
a = arr
print "Size of arr %d\n" % len(arr)
print "Size of a %d\n" % len(a)
def func(arg):
print "%d\n" %(arg)
func(5)