Using == operator in better way in cpp

In cpp, it is possible that instead of
i==5

we can do

i=5

So we assign i = 5 and if it is like
if(cond)
cond gets true.

So better is
5==i
beause == is symmetric.
If someone writes by mistake is
5=i
As we get error = ‘can’t assign value to literal’.

Pointer cause decay, references do not.

Decay means loss of type information. In C and C++, an array name ‘decays’ to pointer to the first element. The information lost is basically the number of elements in the array. This difference should be manifested by sizeof() operator in function f() and g(). References keep that information with them. such as ‘constness’ of int. Function names are also said to ‘decay’ into pointer to the function if only function name is used. [Read More]

References and Constants

What is a reference? A reference is nothing more than an alias. Anything you do with a reference you are actually doing to the object you are referencing. float x=3.14; float& intref=x; // intref is a reference to x float* ptr=&intref; // ptr holds the address of x float y=2.58; intref=y; // x is now equal to 2.58 Another simple example: void func(float& fr) { fr=99.99; } int main() { [Read More]

Writing a DLL in C++

Many people incorrectly think the C and C++ languages are the same. Although C++ evolved from C and C++ compilers can compile C, the functionality of the two languages is different. C++ is a complete object-oriented language. It supports inheritance, information hiding, polymorphism and operator overloading. C does not have these features. C++ was originally implemented as a pre-processor to a standard C compiler. The pre-processor parsed the C++ source code and generated C source. [Read More]

C++ STL: Iterators and Containers

This article was contributed by Eric Sanchez Environment: ANSI C++ As one explores further into the standard template library, there must be a basic understanding of a few trivial terms. Perhaps the two most important are containers and iterators. Container Classes As the name implies, instances of container classes are objects that “contain” other objects. C++ STL comes with a rich set of such components that aid in storing collection of values. [Read More]

how to chk if a no. is integer or not.

Source : http://stackoverflow.com/questions/784563/c-check-whether-is-number-is-int-float/784825

#include
using namespace std;
int main(){
 double num1;
 cin»num1;
 if(static_cast(num1) == num1)//casts num1 to type int
  cout«"Integer"<
 else
  cout«"Not Integer"<
  return 0;
  }

Another method is

char  *test =  "asdf1234";  
int i;  
for  (i =  0; i < strlen (test); i++)  
{ if  (isdigit (test[i]))fprintf (stdout,  "test[%d] is a digit!\n", i);  
}  

Bubble sort

The sorting problem Input: Array of numbers , unsorted. Eg. Output : Same numbers sorted in some order, say increasing order. Eg. What is Bubble Sort? The bubble sort works by comparing each item in the list with the item next to it, and swapping them if required. The algorithm repeats this process until it makes a pass all the way through the list without swapping any items (in other words, all items are in the correct order). [Read More]

Stack implementation using linked list

We will be understanding the stack implementation using linked list. So, please understand the link list before proceeding. Lets understand how we can implement the different operation using linked list. CPP implementation Here is how we use linked list to implement stack in cpp: #include <iostream> using namespace std; struct node { int info; struct node \*next; }; struct node \*top; int empty() { return((top == NULL)? 1:0); } void push(int n) { struct node \*p; p=new node; if(p! [Read More]

File handling in cpp

File I/O with Streams: Many real-life problems handle large volumes of data, therefore we need to use some devices such as floppy disk or hard disk to store the data. The data is stored in these devices using the concept of files. A file is a collection of related data stored in a particular area on the disk. Programs can be designed to perform the read and write operations on these files. [Read More]