Sunday, 31 March 2013

Simple c++ program

#include<iostream>
using namespace std;

int main()
 {
  cout << "Hello World";
  return 0;
}


Here are a few observations about this program:
  • This is a Standard ISO C++ program using the standard library. Standard library facilities are declared in namespace std in headers without a .h suffix.
  • If you want to compile this on a Windows machine, you need to compile it as a "console application". Remember to give your source file the .cpp suffix or the compiler might think that it is C (not C++) source.
  • Yes, main() returns an int.

Can I write "void main()"?

The definition
 void main() { /* ... */ }
is not and never has been C++, nor has it even been C.

A conforming implementation accepts
 int main() { /* ... */ }
and
 int main(int argc, char* argv[]) { /* ... */ }
A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.

In C++, main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution. For example:
 #include<iostream>

 int main()
 {
  std::cout << "This program returns the integer value 0\n";
 }
Note also that neither ISO C++ nor C99 allows you to leave the type out of a declaration. That is, in contrast to C89 and ARM C++ ,"int" is not assumed where a type is missing in a declaration. Consequently:
 #include<iostream>

 main() { /* ... */ }
is an error because the return type of main() is missing.

 Ref: http://www.stroustrup.com/bs_faq2.html#void-main

Cyber attack .....

When country attacks another it becomes a big news. When someone attacks other person that also make a news item. But the recent cyber attack was least spoken about at least in the Indian news media barring one channel that had discussed it.

But let us try and find out what exactly happened that caused this attack.This is the information I gathered from various sites.

Spamhaus, an anti-spam company, placed Cyberbunker on their black-list of spam generating companies. Cyberbunker quickly retaliated with a Distributed Denial of Service (DDoS) attack, which essentially is an attempt to make a machine or network resource unavailable to its intended users.Such attacks would saturate the server with communication request making it unavailable.

The initial attack failed. When the DDoS attack failed, Cyberbunker widened the assault by exploiting a weakness in DNS. This weakness allowed the impact of the attack to be magnified by 50 times by using decentralized cyber nodes around the world as a means of attacking these two companies. This meant that although only two companies were specifically targeted, the attack jammed cyber infrastructure worldwide, causing Internet traffic to slow across the world.

First, some background: The attacks originally targeted a European anti-spam company called Spamhaus, which blacklists what it considers sources of email spam and sells those blacklists to Internet Service Providers. The attack began early last week as waves of large but typical DDoS (Distributed Denial of Service) assaults shortly after Spamhaus blacklisted Cyberbunker, a controversial web hosting company. Cyberbunker has not directly taken responsibility for the attacks against Spamhaus.

In a common DDoS attack, hackers use thousands of computers to send bogus traffic at a particular server in the hopes of overloading it. The computers involved in DDoS attacks have often been previously infected with malware that gave a hacker control of the machine without the legitimate owner's knowledge. Hackers use malware (often sent via email spam) to amass large networks of infected computers, called "botnets," for DDoS operations and other purposes.

Spamhaus contracted with security firm CloudFlare to help lessen the intensity of the attacks soon after they began. CloudFlare has been defending Spamhaus by spreading the attacks across multiple data centers, a technique that can keep a website online even if it's hit by the maximum amount of traffic a typical DDoS can generate.

These attacks, have evolved into a complex and ferocious beast, pointing up to 300 gigabits per second at an expanding list of targets. How?

After the hackers realized they couldn't knock Spamhaus offline while it was protected by CloudFlare, they chose a different tactic: targeting CloudFlare's own network providers by exploiting a known fault in the Domain Name System (DNS), a key piece of Internet infrastructure.

DNS essentially turns what humans type into an address bar ("www.mashable.com") to the desired website's IP address and helps to deliver the desired Internet content to a user's computer. An essential element of the DNS system are DNS resolvers — 21.7 million of which are open and able to be found and manipulated by hackers.

Because DNS resolvers are connected to large pipes with plenty of bandwidth to point at a target, hackers can manipulate them to amplify standard DDoS attacks from a maximum of about 100 gigabits per second to the neighborhood of 300 gigabits per second.

Saturday, 2 March 2013

When to use semicolon and when not to......

Are you confused about when to use the semicolon and when not to. Here is a small explanation to make your concept clear.


Roughly speaking semi colons terminate. It tells the compiler that one statement is over.

E.g.

int i; // This statement will declare an integer variable named 'i' terminated with semi-colon
i=10; // This is a statement to assign the value terminated with semi colon


Exceptions

1.Semi-colons are used when setting up a "for" loop - 
the syntax is "for(...;...;...)", 
though their main use is to end statements.  

2. Note that an "if", "while" or "for" statement doesn't end straight after the test condition, they have the block statements to execute if the test condition is true/false/

E.g
      if(x>5)  // this is not the end of statement there are more statement(x) to be executed if the condition is
                     true
         cout << x; // this statement is executed if the condition is true and is terminated

It's not illegal to put a semi-colon there, but it's rarely what you want. 

E.g.   for(i=0;i<5;i++); // this loop has no block statement

Remember we used this kind of loops for getting string length.

char str[100];

cin>>str;
for(int i=0;str[i]!='\0';i++);

cout <<i; // this will display string length. As we had only counting to be done we do not have any other 
                  block statement.

 3. Semi-colon to terminate structure or class definitions.
       struct POINT
            {
               int x,y;    // end of statement
             };  // end of structure

4. Semi-colon to terminate function prototype
       Function prototype is function declaration done to tell the compiler about the function return type, type and number of parameters.

Try reading

http://www.cpptalk.net/confused-about-the-meaning-of-the-semicolon-vt11965.html