Friday, June 24, 2011

No More Confusion with Pointers: A short technical paper for understanding Pointers


Pointers, the concept which a c beginner find difficult to understand. Even if you once read it carefully, you cannot be hell sure that you will be able to work with pointers conveniently. Here is a quick technical article which may help you understand pointers deeply.

Misconception: Pointer is an address to a VARIABLE.

A pointer points to an address, but the address need not be the address of a variable. It may be address of any location in the computer memory. For example,

int i=10, *pi;
pi=&i;
 
Here ‘pi’ is a pointer variable pointing to the location of ‘i’. Be careful, it does not point to ‘i’, it points to its location only. Now if we change either ‘i’ or ‘*pi’, the corresponding value at the location will change. Here 
arises the misconception that ‘pi’ is associated with ‘i’, which is not. Consider the following example:
int *pi;
pi=(int *)malloc(sizeof((int));
/* malloc is a function to dynamically allocate memory to a pointer. It returns ‘void *’, which is typecasted as ‘int *’ */
*pi=1024;
printf(“The value at pi is”,*pi);
free(pi);

Here ‘pi’ is a pointer which points to an integer value. But it does not points to some variable, but a memory location is allocated to it using ‘malloc’.
Hence we conclude that a pointer is a variable which points to a memory location and not particularly the location of a variable.

Wednesday, June 22, 2011

C program to evaluate a polynomial using HORNER’s Rule

Recently I was going through Data Structures in C, and I came to the problem of evaluating a polynomial using Horner’s rule. Horner’s rule is a strategy for evaluating a polynomial A(x) at a point using a minimum number of multiplication.

The following C program is a correct one, but the thing I want to emphasize is trouble with the use of global variables. Lets go through the C code first:
#include<stdio.h>
#include<conio.h>
int horner(int,int);
int count=0;
void main()
{
     /*Horner's rule for evaluating a polynomial */
     /* let us take a0=0,a1=1,a2=2.. and so on */
    
     int n,x,h=0; //n is order, x is value of X in polynomial.
     scanf("%d %d",&n,&x);
     h=horner(n,x);
     printf("%d",h);
     getch();
}

int horner(int n, int x)
{
    int i;
    if(count!=n)
    {
                i=count;
                count++;
                printf("%d+%d*(",i,x);
                return (i + x*horner(n,x));
    }
    else
    {
        printf("%d))=",count);
    return count;
   
}
    
}
Initially I faced a big problem with the above program when I was not using the local variable ‘i’ in the ‘horner’ function. You can check the output with and without the use of ‘i’. The problem was that all the return statements were being evaluated after the last ‘horner’ got evaluated for the recursive function, and in the meanwhile, the global variable ‘count’ got changed every time ‘horner’ was evaluated. Since the return statement depends upon ‘count’, the output came out to be deviated from the expected value depending upon the size of input. Hence the variable ‘i’ came into existence.

Tuesday, June 21, 2011

New Voice Search on Google: Tech Updates

Google Inside Search 2011 Google is now rolling out some of the new search technologies it previewed last week, including search by image and voice search on the desktop.
The features are currently only available via Google's Chrome browser, but they allow you to search on the desktop by voice as well as drag-and-drop photos into image search for details on what's displayed.
For voice search, Chrome users visiting Google.com will see a little microphone icon on the right side of the search box. Click the mic and a small box with the instructions to "speak now" will appear. You'll need a microphone attached to your computer for it to work.
Voice-activated searches are already available on mobile devices like the iPhone and Android-based devices. At its search event last week, Mike Cohen, manager of speech technology at Google, said the company has seen the number of mobile voice searches grow sixfold over the past year.
Search by Image, meanwhile, lets you drag a file from your desktop onto the Chrome browser and have Google analyze it for possible people, places, or things in its database. Add a photo from a family vacation, for example and, ideally, Search by Image will tell you where the photo was taken and more about the region. If you don't want to drag and drop, you can also click the camera icon in the search box and upload an image.
I dropped in a photo of the Brooklyn Bridge, and Google correctly identified the location, offering up other photos as well as links to sites about the bridge. It was not able to identify an image from this morning's Murakami Google doodle, but turned up results for "funny dog pictures" when I dropped in a pic of a chihuahua in a wig.
For those worried about security, especially in light of Facebook's facial-recognition technology snafu, I dropped in a photo of my PCMag headshot. It did not identify me, instead turning up photos of other dark-haired individuals standing against a red background.
For more, see the slideshow above.
Over the weekend, meanwhile, a possible redesign for Google's search result pages was spotted by PCMag's David Pierce. It ditched Similar page links, added a splash of color, and added that voice microphone button.

How to Back Up Your Blogger Blog

Do you know how to back up your Blogger blog? There can be nothing worse than to login to Blogger one day and find you blogger blog gone, corrupted or deleted forever due to any unforseen error. Back up is very important. Here are a few simple ways to keep your Blogger blog safe and backed up….

Back up Blogger Posts

  • Backup Your Posts – Bloggers Blogsend allows each of my blog posts to be automatically sent to my email address. So I have a back up of all my posts as individual emails. You can further create folders in your email account (as in Yahoo Mail) or apply labels (in Gmail), and create filters such that such emails can be collected in one place.
  • Back up your entire blogger blog – Bloggers provides detailed instructions to create a single file with all your posts which you may publish and then copy to your own computer for use as desired. Remember to save a copy of your existing template in a file on your computer as you will need to have it at hand after this process is completed. This is good for a one time backup, but is cumbersome to do if you back up very frequently. Also you might mess up some setting and disbale your blog is not done right.
  • Try third party back up tools – like the HTTrack Web site copier for Windows users and Webgrabber for Mac users. Each of these applications will create a fully working, interlinked local copy of your blog for browsing offline and easily allow you to back up. Remember it will take considerable time and internet bandwidth if you have a huge blog.

Back up Blog Template

  • Back up the template whenever you change it. Just copy and paste the entire template code into any simple text editor like Notepad or Wordpad and save file with name like ‘myblog-date.txt’. After a while you will have a series of such files organized by date. If for some reason your blog goes away, just copy and paste the teplate back into Blogger and republish.
  • If you have lost your template partly or fully – learn how to restore your blog template code and then back it up.

Back Up Blog Comments

  • Blogger has an option to send you an email when someone leaves a comment on your blog. This is located in Setting > Comments option in Blogger. This enables you to collect all your comments as individual emails, much like the blogsend posts emails mentioned above. Then you can file them all together as labels or in a email folder.
  • If you moderate comments, you can get all your comments as emails pending your approval. This email address can again be entered in Setting > Comments. If you do not want to save rejected comments as emails and recieve only published comments – then you can keep the comment moderation email address blank, while filling up the Comment Notification Address.
  • If you use Haloscan Comments instead, then anyway your Blogger comments are off and Haloscan is keeping track of backing up your comments. I am using Blogger comments featured now with comment moderation, word verification captchas to combat comment spam.
Make blog back ups a habit and you will remember this post when it saves your blog on a bad day!

Sega Hack Affected 1.3 Million Users


Sega LogoSega on Monday confirmed that a recent hack of its system affected almost 1.3 million customers. Hackers who infiltrated the Sega Pass system last week gained access to 1,290,755 customer accounts, which included Sega Pass members' names, email addresses, dates of birth, and encrypted passwords.
"We express our sincerest apologies to our customers for the inconvenience and concern caused by this matter," the company said in a statement. "Sega Pass is the service used to provide information about our new products to registered members and does not hold any customer financial information."
Sega said it checked its other services and "can confirm there are no other verified incidents."
After the intrusion was detected, Sega took its Sega Pass service offline and "took emergency action to prevent further damage," the company said. "This action included immediately contacting all our registered SEGA Pass users. We are now fully investigating the cause of the incident." Sega promised that network security will be a "priority issue" going forward.
Hacker group LulzSec has been targeting a number of gaming companies, including Sony and Nintendo, but they denied involvement with the Sega intrusion and even offered up its assistance.
"@Sega - contact us. We want to help you destroy the hackers that attacked you. We love the Dreamcast, these people are going down," LulzSec tweeted on Friday.
LulzSec had similar sentiments earlier this month. "We love Nintendo and Sega, if anything we'd hack *for* them. If you're listening Nintendo/Sega, you, you uh... you want Sony hacked more?" the group said on June 6.
LulzSec said today that it is teaming with Anonymous to target government Web sites.

ICANN Approves Plan for New Domain Names

ICANN logo The Internet's governing body on Monday approved a plan to increase the number of generic top-level domains (gTLDs), which could significantly increase peoples' options when it comes to domain names.
At this point, there are 22 gTLDs, including .com, .org, and .net. The Internet Corporation for Assigned Names and Numbers (ICANN), however, have approved a plan that would allow people to apply for new gTLDs, like .pcmag, for example.
"Today's decision will usher in a new Internet age," Peter Dengate Thrush, chairman of ICANN's board of directors, said in a statement. "We have provided a platform for the next generation of creativity and inspiration."
That creativity won't come cheap, however. Applicants must pay a $185,000 evaluation fee, with $5,000 upfront. They might also be required to pay even more "in certain cases where specialized process steps are applicable," in addition to business startup costs, ICANN said.
ICANN will soon kick off a global campaign publicizing the new gTLD option, and will accept applications between January 12 and April 12. When the application period closes, ICANN will publish a list of all requested gTLDs, at which time people can file objections.
The actual evaluation process could take between eight and 18 months; ICANN has a lengthy applicant guidebook against which applications will be assessed. If you wanted to apply for two similar or related TLDs, you would have to file two applications—and pay two $185,000 fees. But ICANN warns that "the application process is currently designed to not allow two strings that are 'confusingly similar' to each other."
Once it's approved, meanwhile, "the applicant is required to conclude an agreement with ICANN and pass technical predelegation tests" before the gTLD will be live on the Web, ICANN said.
If you miss your window next year, ICANN expects to hold additional application rounds in the future.
"ICANN has opened the Internet's naming system to unleash the global human imagination. Today's decision respects the rights of groups to create new Top Level Domains in any language or script. We hope this allows the domain name system to better serve all of mankind," said Rod Beckstrom, president and CEO of ICANN.

Sunday, June 19, 2011

Six Free C\C++ ebooks by Microsoft


C \ C++ logo
This week Microsoft announced that it's working on making C++ better suited for massive parallelism. This follows Google's recent benchmarks that showed that C++ is still faster than most programming languages (at least if you know how to optimize it correctly). Also, Google has been working on incorporating C and C++ support into Chrome.
In other words, C++ is a strong and important language, and will continue to be even in a browser dominated landscape. Here are a few resources for leaning C++, and its predecessor C.
Introduction to C Programming
You don't need to know C to learn C++, but many C++ books assume knowledge of C. If you're completely new to programming and want to learn C++ from a free book, please see How to Think Like a Computer Scientist below.
However, if you are new to programming and want to start with C, you might want to start with Introduction to C Programming by Rob Miles. A PDF version can be found here.
Miles has also written free e-books on C#.

The C Book

The C Book
The C Book by Mike Banahan, Declan Brady and Mark Doran is an introduction to C for experienced programmers. The print edition, first published in 1991, is no longer in print.

How to Think Like a Computer Scientist C++ Version

How to Think Like a Computer Scientist C++ Version is the C++ 'port' of Allen B. Downey's classic introduction to programming. The Python version has been used by MIT for its introduction to programming. It assumes no prior programming experience.
There are also versions in Python and Java, and a Ruby version is in progress.

Thinking in C++

Thinking in C++ cover
Thinking in C++ by Bruce Eckel aims to 'move you, a little at a time, from understanding C to the point where the C++ mindset becomes your native tongue.' It's written with the expectation that the learner have existing knowledge of C syntax. It begins by introducing object oriented programming and moves into covering more advanced C++ over the course of two volumes.
A print version is also available.
Eckel also wrote Thinking in Java which we included in our round-up of free Java e-books.

C++ Annotations

cpp_annotations_0611.jpg
C++ Annotations is a free e-book by Frank B. Brokken of the University of Groningen. He uses it as the primary text of his course on C++, and it's written for programmers already familiar with C.

Visual C++ 6 Unleashed

Unleashing Visual C++
Visual C++ 6 Unleashed by Mickey Williams and David Bennett covers programming in C++ using Microsoft's IDE. A print version is available as well.

Want Even More?

There are many more free e-books on C and C++, including many on more advanced topics. You can find more here, here and here.
If you want to learn C# or Objective C, we have separate round-ups for you here and here.