Pointer in C/C++ Part – 1

Wanted to start such posts for a long time. After Abhay posted his queries related to pointers, I decided better late than never. I’ll try to post such stuff more frequent. :)
Will always be looking forward for your feedback.

What is a pointer?
Pointer is a variable that stores an address as its value.

How to declare a pointer?
To declare a variable as pointer we have to use “*” along with variable name, in its declaration. Following declaration declares variable i as a pointer to integer.

int *i;

“*” in the declaration is associated with the variable name, which means in the following declaration while i is a pointer variable, j is of integer.

int* i, j;

The correct way to declare multiple variables as pointers, in same statement, is by adding “*” before each variable name, as shown below.

int *i, *j;

Another way would be to use typedef to create a new type and use that to declare variables of that type.

typedef int * INT_PTR;
INT_PTR i, j;

Pointer initialization.
While it is ok not to initialize a static and global variable, as they are by default initialized to 0 (zero), it is always better to initialize a local variable, to avoid using the garbage value stored in it. Since a pointer stores an address, it becomes more important to make sure we initialize a pointer to a known value, as accessing a random (garbage) address can result in core dump (linux)/segmentation fault (windows).

Now the question is how do we get a valid address to initialize a pointer variable?

One way is to initialize a pointer with the address of a existing variable, as shown below.

int i;
int *p = &i; // Initialize pointer p, with address of variable i.

Another way is to dynamically allocate memory and use that address to initialize the pointer variable, as shown below.

int *p = (int *) malloc(sizeof(int));
int *q = new int; // Only for C++ programs.

One more way is, this should be used very carefully, to initialize pointer with a “known” address. This known address might be of some memory reserved by OS and documented. In this case we specify the address as a integer and typecast it to pointer type, before storing it in pointer variable, as shown below. When storing integer into a pointer in the following way one must be very careful in doing so becuase after storing that integer into a pointer, any access of that pointer variable will access the contents of the memory address at the integer location.

int *p = (int *) 0×0417; // Address of a byte where MS-DOS stores status of some keyboard keys.

New Year Special – Ghats near Pune

Lavasa Curve

It’s a belief that what ever we do at the start of New Year, we will keep doing that for the rest of year. I wanted to ride out on 31st night but then family and friends had some plans so I decided to party instead.

Couple of days later, it was the first weekend of year and I decided, better late than never. So, I head out to some near by places. Saturday ride was sort of warm up and hence it was just 103km trip, a slow one at that (Ride duration: 2hrs 45min).
Lack of interest in riding on straight roads, I decided to head to near by twisties and sure it was fun even at speeds around 50km/hr (yes, I was running in my bike after a new block piston kit).

Lavasa Curve

The route I took was Chandani Chowk – Mutha – Lavasa – Mutha – Pirangut – Paud – Hinjewadi.

Sunday I decided to head towards Mahabaleshwar, while I was cruising on NH4 at yawning speed I realized I’m not carrying my bike’s original RC book (often documents are checked at Panchgani, only of two wheelers, as if we are criminals while people in cages are all saints). So when I saw a familiar turn off NH4, I jammed my brakes (must have put down a few mm’s of rubber on tarmac) and got off the boring highway. This was the road I have taken for the last time in Jun’03 (when we went for Pulsar Yahoo Group’s Annual meet). This is a lesser known (to travelers) road that takes you to Bhor. Yes, I dumped Mahabaleshwar in favour of Bhor and Varandha Ghat.

Enroute VarandhaEnroute Varandha

The nature of road hasn’t changed much once we cross Bhor. Though its pothole free tarmac almost all the way, there is plenty of gravel on both the edges and in center. I love it, you over cook a curve, run wide and either you will go off the road or can go and kiss mother earth.
Varandha Ghat CurveVarandha Ghat Curve

Since rains have just gone by, water levels are good in the dam en-route.

Backwaters of Neera DamBackwaters of Neera DamBackwaters of Neera Dam

After a small break for hot bhajis and tea in Varandha ghat I headed towards Mahad. It was closing on 5pm and I knew I’ll have to climb back in dark, on my way back. Having climbed Tamhini in dark few days back on CBZ, I wasn’t too worried of taking the same route again.

Varandha Ghat's Valley ViewVarandha Ghat

Once I reached Mahad, I saw Poladpur (to go towards Mahabaleshwar) some 15km’s away and there was no distance to Mangaon (to go towards Mulshi) given, I guessed that Mangaon can’t be too far away so I headed towards it, after few km’s I realized my mistake as it was still some 30km’s away and the sun has started to go behind hills. By the time I reached Mangaon it was 6:15pm and after filling some fuel (yeah twice I have started the climb to Tamhini with bike about to hit reserve – no way was I going to repeat that mistake).

The Mangaon – Vilhe road was almost empty of traffic and in lovely condition. Even though it was dark, it was fun riding in that section filled with twisties. After Vilhe, I decided to stay with couple of cars that were climbing Tamhini but with me not wanting to stress my new engine, mid way thru the ghat one car was too fast for me while the other was too slow, as a result I was left all alone. It was a bit scary and I was remembering only all the scary stories I have heard about this area. Hoping to catch some slow moving vehicle ahead, I kept on riding but I wasn’t that lucky. Once I passed the last dhaba on top of ghat, it was me and my bike all alone. Other than my bike’s headlamp, moon and stars were the only light sources visible. I wanted to stop and click some pictures but wasn’t able to gather enough courage to do so. After riding all alone for some 15min’s I caught up with some traffic as the bad stretch of road has started. Then on it was just a matter of keeping up with them.

Following with vehicles I reached Mulshi lake and what a beautiful view it was, I told myself I’m coming back here in night again, of course not alone :-) . As I was feeling hungry, I halted for dinner and then it was a slow cruise till home.

Route: Pune – Bhor – Mahad – Mangaon – Vile – Tamhini – Mulshi – Pune
Distance: 300km’s
Ride Duration: 8hrs 30min

Click on image to view in bigger size.

Panning & Moon’o'graphy – 2

Today I was out again in night sharpening my panning shots. Lday luck was with me and the very first shot came out almost perfect (to my liking). As I was hand holding the camera, I started with ISO1600 and hence some grain can be seen in the image.


Clicked using Canon 70-200 f/4 L lense on 400D, shot @ ISO 1600, 188mm, f/4 and 1/10sec shutter speed.

Motivated by my effort, I got the tripod out and started to practise on the moving objets. Now, I was able to bring the ISO down to 400 without too much blurr as I was no more hand holding the camera. Following is one of the many clics.


Clicked using Canon 70-200 f/4 L lense on 400D, shot @ ISO400, 145mm f/4 and 1/5sec shutter speed.

While I was out, I also decided to capture the white moon, almost in its full shape.

Clicked using Canon 70-200 f/4 L lense on 400D, shot @ ISO100, 200mm f/8 and 1/125sec shutter speed.

Similar topics
Panning – My Debut shots
Moon’o'graphy

Panning – My Debut shots

My Pan Shots

Last night as I was done shooting moon from my house balcony, I looked at the well illuminated empty road, some 100m away from me. Tried to click some shots but due to not using a tripod most of them didn’t came well. In between I clicked a zooming car and thats when I decided to try my hand at Panning. Due to low light condition, I had to use higher ISO and really slow shutter speed and hence shots were having too much noise/not sharp enough.

So today morning I decided to venture out once again and here are some of the shots I managed.

My Pan ShotsMy Pan Shots

My Pan ShotsMy Pan Shots

Click on image to view in bigger size.

So how did I clicked them?
I used a slow shutter speed (resulting in larger f-stop/small aperture) and switched between “One Shot” & “AI Servo” (or something like that). Moved the camera along with the moving car/bike. Click and kept moving, when I didn’t moved the camera as I clicked, the object came blurred.

What is Panning?
In simple terms, its about clicking a picture by keeping the moving object in the frame by moving the camera along the object and clicking it at the same time. This will blurr out the background, giving a sense of motion in the image.

For these shots I used my Canon 400D with 70-200 f/4 L lense.

Welcome to 2009

A belated New Year wishes to everyone. Well, I got my New Year gift a bit early. Following is the picture of the gift, my son, born on 21-Dec-08.

My Son

Click on image to view in bigger size.

Just the way everyone make new year resolutions, I have made myself a few and you can see some of them right here in next few days.

Moon’o'graphy

In Nov’08 when I had Canon EFS 55-250 f/4-5.6 IS Lense of my friend lying around I saw this bright object wandering in dark sky filled with stars. I realised I haven’t captured this bright object in my camera ever, not becuase I never thought about it but it was due to lack of enough zoom at my disposal.

The bright object ala Moon as captured on 11-Nov-08.

Full Moon

Moon as captured on 20-Nov-08.

Moon

Click on images to view in bigger size.

A Lap on CBZ

8-9 Dec 20082007: My debut on a race track and what a fun filled it was. I’ll put the entire experience in words later (I know, its almost a year now). For now enjoy a small video, a lap on the CBZ around the track.

Thanks to Motor (Suresh) for shooting the video.

Yamaha R One Five (R15) – The Number’s

Yamaha R15

After months of speculation all over the internet in various discussion board/forum, Yamaha has officially announced the much awaited figures of the R15.

With the rumors quoting power of the bike in excess of 20bhp, the official figure stands at 17PS. Reading the response, I believe Yamaha officials were very smart in keeping the figures secret until the last day else the comments like following would have been floating on the various discussion forums for months.

“Just 17PS”

“My XYZ bike makes more power”

“My ABC bike is just behind in power”

After all discussing all about a bike, without even test riding it, is a born right of every internet savy “biker” :-) .

Now with the gearing numbers also out, I entered them into my Excel spreadsheet and the numbers I saw were a bit shocking.

Primary Reduction: 3.042

Secondary Reduction: 3.000

Rear Tyre size: 100/80×17

Ratio ->

2.833 1.875 1.364 1.143 0.957 0.84
RPM 1st Gear 2nd Gear 3rd Gear 4th Gear 5th Gear 6th Gear
1000 4.32 6.52 8.97 10.70 12.78 14.56
2000 8.63 13.04 17.93 21.40 25.56 29.12
3000 12.95 19.57 26.90 32.10 38.33 43.67
4000 17.27 26.09 35.86 42.79 51.11 58.23
5000 21.58 32.61 44.83 53.49 63.89 72.79
6000 25.90 39.13 53.79 64.19 76.67 87.35
7000 30.21 45.65 62.76 74.89 89.45 101.90
7500 32.37 48.91 67.24 80.24 95.83 109.18
8000 34.53 52.17 71.72 85.59 102.22 116.46
8500 36.69 55.44 76.20 90.94 108.61 123.74
9000 38.85 58.70 80.69 96.29 115.00 131.02
9500 41.01 61.96 85.17 101.64 121.39 138.30
10000 43.16 65.22 89.65 106.99 127.78 145.58

PS: The above numbers are based on the gearing of the bike. They do not take into account the clutch slip, air drag and other such factors.

Now with the bike making max torque at 7,500rpm (15Nm), the cruising speed can be 109km/hr in top gear. With the max power being made at 8,500rpm (17PS), a speed of 123km/hr should be easily attained. Now these are just numbers, how quickly bike can reach there, will only be known once someone is able to strap a data logging equipment to the bike.

Going by just the numbers, I belive the bike should be able to meet the claims of Yamaha official that this bike will be the fastest amongst all Indian bikes, in straight line.

So, how do these numbers fare against ZMA and Pulsar 220 DTSFi? I’ll put up the charts for those two bikes in next few hours, just for some more number munching. That reminds me, its lunch time now :-) .

The official specifications can be found on Yamaha’s website.

May’08 Track Day: Kari Speedway, Coimbatore.

It was yet another track day organised by Anand at Kari Speedway, Coimbatore. My second visit, in a row. This time due to various reasons I was not able to take my bike. Thanks to Killer (Sameer) who loaned me his Apache, I had a ride for the track day.

Now, I’ll not waste too much of time, enjoy some of the pictures.

20080511IMG_1689 20080511IMG_1690
20080511IMG_1691 20080511IMG_1692
Speedy entering chicane on Apache.

20080511IMG_1724 20080511IMG_1728
20080511IMG_1754 20080511IMG_1757
Subhash on RTR pulling stoppie and wheelie.

20080511IMG_1770 20080511IMG_1771

20080511IMG_1772 20080511IMG_1773
Dinesh on RTR through bowl.

20080511IMG_1776 20080511IMG_1777
20080511IMG_1778 20080511IMG_1779
20080511IMG_1780

Subhash on RTR through bowl.

20080511IMG_1783 20080511IMG_1784
20080511IMG_1785 20080511IMG_1786

20080511IMG_1787
Nav on Apache through bowl.

20080511IMG_1790 20080511IMG_1791
20080511IMG_1792
Joel on RTR through bowl.

20080511IMG_1803
Dan’s RD through bowl.

20080511IMG_1804
Keerthi on Shogun through bowl.

20080511IMG_1819

Nav on Apache through last corner.

20080511IMG_1821
Bike discussion in pit lane.

To view image(s) in larger size, click them.
Edit: Thanks to Kathir (friend of Dinesh) for taking the bowl pics.

Lightning – 1, Photoshoped

Lightning Photoshoped

The above image was created by merging the following two images and did some cropping, along with exposure correction.

Similar topics
Lightning – 1