Hello World!

Tuesday, August 31, 2010

It is a very commonplace question for technical interviews that tests your proficiency in C. The problem is quite well-known and so is its solution. The objective is to print two string literals say "Hello" and "World" using two printf statements where one printf should be a part of an if block and the other a part of its matching else. The most common solution is

if(!printf("Hello "))
{}
else printf("World");

Being aware that printf returns the number of characters printed on screen (in case of Hello, it is 5) which we negate using the logical operator ! to make the entire expression as 0 implying false and thus the else part is executed.

Now what if, you were restricted to use any of the logical operators for achieving the same job. Well, here's a solution. The most undermined comma (,) operator plays an interesting role in doing the job:

if(printf("Hello") , NULL) //we can even write 0 instead of NULL
{}
else printf("World");
Note in C, the comma operator has an interesting semantic. All expressions separated by comma's are evaluated from left-to-right however the value of the entire expression is the right-most expression. i.e a= (5+2,3+5,6*4); then a gets the value 24, though all the previous expressions are evaluted. Now using this feature, the if condition part is well explained.

If someone can come up with a more compact and cryptic solution to this, do post it here.

Read more...

My take on Holmes.. Mr. Sherlock Holmes...

Wednesday, August 4, 2010

Never was I an ardent book-worm to turn to classics. For good books are like rare wine and unfortunately I've tasted only a handful of them. For my reading habits get honed up only when I come to know about a best-seller. However, lately, I'd been sitting quite idle post my University degree, which compelled me to raid my bookshelf in the hope of getting something interesting to engage myself upon.


Frantic searches led my hand on a book whose front-page bears my school's emblem with a small message of good luck, reminding me how I walked up the podium to collect this book as a souvenir during our farewell party in the year 2004. Six years hence I thank my school for having gifted me this book which kept me enthralled until I came to the tragic end. It brings me a lot of shame for not having experienced such a recognized collection.

Arthur Conan Doyle has laid before the world some criminal framework which we seldom come across in modern thrillers. Every little adventure has a slow beginning, but the best part is, it suddenly draws the readers full attention into some "tragic case" and you feel arrested until you reach the climax. Over and again I've tried reading a piece in parts but failed in every attempt. My chosen five adventures out of the 24 selected ones, in their order of ranking, would undoubtedly be:
  • The Speckled Band
  • The Red-Headed League
  • The Five Orange Pips
  • The Engineer's Thumb
  • The Adventure of the Beryl Coronet
Although I've dared to make selections out of the 24, but I'm sure every Holmes lover would've appreciated the "Sign of Four" which depicts some unparallel methods for crime detection.

I fancy that the most unfortunate adventure as a reader, must be the "The Adventure of the Final Problem" which eventually causes Sherlock's death and termination. I know, that the ardent subscribers' of the Strand Magazine that time, roared against the termination of such a mesmerizing character and the popularity was such, that it led to new series "The Return of Sherlock Holmes". However, I'm still looking for the other collection namely
"The Casebook of Sherlock Holmes" , "The Hound of Baskervilles" and "The Best of Sherlock Holmes".
I'm ready to cough up a price for a used copy, if someone is ready to sell off, although I doubt whether someone has the courage to shed off such collection from their shelves in return of a scanty sum...



Read more...

"C" the intracacies

Sunday, May 30, 2010

The other day, one of my nerdy mates, Rajdeep had put forth this problem, which caught me on the back foot. Apparently, the problem appealed like a fundamental predict the output snippet, but the exact reasoning is yet to be found. Following is the code snippet with some steps, someone needs the explain the reason behind such a weird output.

//File name: googly.c
#include
int main()
{
int a,b;
a=((b=5)+1); //Line 2
printf("a=%d b=%d",a,b);
return 0;
}

As you would have expected Line 2 essentially reduces to two sequential statements, b=5 and then a=b+1 and you get the result 'a'=6 and 'b'=5;

Now try replacing Line 2 with the expression a=((b=5)++)and then try to compile using a standard C compiler and you would observe an compilation error. You might come across a logic to explain that error.

But the strange behavior doesn't end here, save the code with a .cpp extension, compile it with a standard C++ compiler & you'd be startled to note that the error is gone and the program runs seamlessly to produce the output as a='5' and b='6'.

I suppose there's some compilation issue that makes it happen, but need a succinct logical explanation to this. Your reasonings are awaited...

Read more...

The Riches to Rag Story

Friday, April 30, 2010

The brouhaha over IPL is strong enough to stay in the hearts of every cricket maniac. However, this year IPL has been a nightmare for the persons acting as the backbone of the entire institution. Whatever, may be the issue, my sentiments associated with the game is strong enough which leads me to say IPL Must Stay Back at any cost, no matter whoever rules as the chairperson, irrespective of the filth and corruption associated with it.


With that, I don't want to mislead the readers, I'm not here to put my opinion behind the IPL issue,for debate on that issue, every Indian News Channel is doing better in dissecting every inch of it. Rather I'm to put forth a humorous condemn report "The Riches to Rag Story". It goes like......

Prior to being caught red-handed:

"Mr. Lalit Modi was surrounded by Preity Zinta,Shilpa Shetty, Deepika Padukone & the respected Shahrukh Khan.... This was coined as THE AXE EFFECT!!! "



After his empire got busted
"Mr. Lalit Modi is now being surrounded by top-brass Income Tax Officers!! They call it the...........
TAX EFFECT!!!! " LOL!!


Read more...

30 days of Unpredictability and more...

Saturday, March 20, 2010

Its like around the World of Unpredictability in 30 days. Feb-2010 to March-2010 would probably be the fastest journey I've ever made till date. Unpredictability and confusion has bee the integral part of my life and career for, the past 2 years, but the past month was undoubtedly the most hectic of them.


With my ailing father suffering from acute renal failure, I had to leave for Chennai on the end of January 2010 for his immediate treatment. That was the first instance when unpredictability started following my footsteps. The domestic flight we availed to reach Chennai underwent a mid-air technical snag, that left us stupefied until it got grounded. Well there was more to that, the flight ultimately helped us reaching our destination at 2 am in the night leaving us stranded at the airport until daylight. Finally the treatment commenced and the results wasn't really positive. Somehow, that unwanted journey came to end.
Received glitters of hope on reaching home with the notification that campus drive is round the corner. Naturally, I started working on it steadfastly until that unwanted notification arrived that it got deferred. With that, I was like thrown up in the air, without even a parachute. What came as a blow was the notification of the semester which was to be held in a weeks time,things were completely in a mess. However I managed to divert my course of action to work for the new objective, the so called Semester a.k.a the Rat Race. With zero preparation, I's fearing a massive ordeal with the papers, especially VLSI but somehow the exams were through, beyond my horrendous expectations. Still unpredictability prevailed. The results got published which left me shattered into innumerable pieces... In fact I kept abusing my respected profs for the entire week, for honoring me with those undeserving scores. Still, I's right back on my feet to look up to the next objective, campus recruitment-yet another Rat Race.

The three-day long campus recruitment process was yet again an instance of uncertainty. The initial aptitude test went haywire when my verbal abilities was questioned with alien like words and passages. I still doubt how we all managed to see through that test. But the day following it. was the most disheartening and
unpredictable one. People who never cared for the job got selected and some who'd put in their heart and soul in it were left out. It literally left us into tears, it was indeed an out-and-out injustice and a manifestation of the unpredictability associated with the corporate world!

Bagging a job is just another beginning to a new series of unpredictability, that's what my realization is, coz the day is not far when I might get fired despite my technical skills although a non-tech ass*** would still carry on with a job, which he's not meant for.....

I can sense more is coming up on this unpredictable journey ahead and unfortunately I've no plan as an alternative.....

Read more...

  © Blogger templates Newspaper by Ourblogtemplates.com 2008

Back to TOP