Monday, 30 May 2016

Normal user in linux or unix is restricted to create file descriptor after a certain value.  Normal user cannot create a fd more than the allowed limit.
This limit was set by the root user to the normal users. To know threshold of fd can be created, just  use the following command

ulimit –n

There are two types of limit
  • Hard limit
  • soft Limit

Hard Limit

Hard limit was set by the root user. Hard limit  says maximum number of fd that the user was allowed to create.
 Normal user can modify the hard limit but normal user can decrease the hard limit but normal user cannot increase it.

To know about the hard limit

ulimit –Hn

To set the hard limit
ulimit –Hn 100

This means that hard limit is set to 100.

Soft Limit

soft limit  says maximum number of fd that the user was allowed to create.

Then what is the difference between hard and soft limit?

If hard and soft limit both were same then limit to user is also same value. But If hard limit is higher and soft limit is low then soft limit is the limit value.

Then why we need a two types of limit?
Hard limit is used to restrict the Normal user to go beyond the allocated limit. Soft limit is used to set the limit according to their need. Say suppose Root user allocates limit as 100. then if you don’t want 100 to be set. Then you can change the soft limit to 50. So your limit is 50 now.
Normal user can  change the value of the soft limit (Not more than the hard limit). So the user has the control to set the limit according to their needs.

Soft limit is one which is equal or less than the hard limit. Soft limit cannot be greater than the hard limit.

To know about the soft  limit
ulimit –Sn

To set the hard limit
ulimit –Sn 50

This means that soft limit is set to 50.

The soft limit and hard limit you set during that session  is not permanent. It will be reseted to default value while starting a new session.
Whether any performanace impacts will occur when we declare variable inside and outside of for loop in c  or c++ programming?

I think your answer will be yes.
But my answer is no(Terms and conditions apply) for POD types.
There will not be any performance impacts when declare the variable inside and outside the loop. But this depends upon your type is POD or non-POD Type.

Why there is no performance impacts for POD Types:

Compiler will do some magic in the name optimization for POD-types alone.
When you declare a variable inside the loop, compiler will optimize in such a way that it will not allocate memory for that variable for each iteration rather it will keep the variable as register. So no memory allocation is required at each time of iteration.

Why terms and conditions apply?

Remember this purely depends on your compiler. Standard is not giving guarantee for this.
If case your compiler is showing the performance impacts, then better you should throw your compiler.
Consider this for loop example:
for (int i=0;i<10;i++)
int a=10; // There is no performance impact because compiler will optimize it
MyClass obj; // There is performance impact

What about non-POD types like class or struct?

Yes there will be performance impact for the non-POD types this is because constructor need to be called at every iteration.

Saturday, 28 May 2016

Because arrays are implemented similar to pointers in c and c++.
Array is not completely a pointer, but arrays  behaves like a pointer which will depend upon the situation where you were using in code.
Now consider one int array example:
int a[10];
In the above int array example, I have declared int array a with size as 10.
Here compiler will allocate memory continuously with first element of the array pointing to the first element.
Consider element of the first address as 1000.
Just hold on up to here, let me teach you about subscript operator.

What is array subscript operator in C or C++?

            Operator which is used to access the array element is called array subscript operator or index operator.
Array index operator [] example:
            int a[10];
How this index operator works in c or c to access array element?
Consider you were accessing third element in array like a[2]
Here how compiler will access the third element is like following
Compiler will change the a[2] in to  (base address of a + 2).
Hope you noticed. So, whatever number you were giving accessing array element, compiler will add it to array base address and it will access the element.
So how to access the 1st element in the array.
You have to add 0 to the base address. The base address of the array contains the 1st value of the array .i.e., arr[0]. Compiler uses the a+0.  To This is the reason array index is starting with zero instead of one.

Another technical reason for array index starting with zero:

Not only for offset purpose the array index was starting with zero.
There is also another reason which is considered by the compiler designers and computer scientists to start the index with 0.
We need to consider how much memory array index value takes to store in memory.
To represent the b power n values we require an n bits to store array index  in memory if index started with 1.
Seems to be confusing, Look at the example below
For Eg, Consider you want to represent the 8 array elements in memory.
If you start with 0 (0-7) we will required for 3 bits to represent in terms of binary.
If you start with 1(1-8) we will be required 4 bits. Because 8 cannot be represented using the 3 bits it requires an additional 4th  bit.
This is the reason why addressing the memory in computer system also starts with zero instead of 1.

Thursday, 26 May 2016

Whenever you call a c function or C++ function, compiler will expect the function definition or function prototype as declaration.
Whether C or C++ programming will allow calling the function without function declaration?

Example program:

int main()
myFunction(); //calling without pre declaration,
  return 0;
int myFunction()
  return 0;
Answer is yes in case of C programming(Terms and condition will apply) and answer is no for C++ programming.

Calling function in C programming function declaration:

Function with return type as integral value no need to be declared or defined explicitly in the C programming.  
So then what is that terms and conditions?
When your return type is  not a integral value, then you have to explicitly define  or  declare the function . If it is not defined then compiler will throw an error like, I can’t found “function declaration” or “function definition” for the function you called.

Calling function in C++ programming function declaration:

For c++ it will not compile for all return types irrespective of the return type of the function

Tuesday, 24 May 2016

Is below program will compile?


class test
   int a[];
   char b[];

int main()
   test t1;
   return 0;

OUTPUT: No compilation error. Array with empty size is allowable syntax in c and c++.

Monday, 23 May 2016


struct structhack
   char a[0];

struct no_member_struct

int main()
   printf("\n  :: %u ", sizeof( structhack ) );
   printf("\n  :: %d ", sizeof( no_member_struct ) );
   return 0;

:: 0
:: 1

Sunday, 22 May 2016

Bitcoin is kind of digital money invented by Satoshi Nakamoto appeared in the year of 2008. Unlike traditional money, you no need to carry the bitcoin, whenever you purchase something. It is a kind of crypto currency.
Transfer of fund in bitcoin is nothing but transferring the bitcoins from one electronic wallet to another wallet.

bitcoin logo

Decentralized payment network

Bitcoin is a decentralized payment network.

So, what is decentralized?

It is nothing but payment is transferred between user to user without any centralized authority. No mediators will involve between the sender and receiver in the decentralized payment network. Where as mediators will involve in the transfer of money in the centralized payment network. For instance money which you transfer through bank is a centralized because bank is mediator between the sender and receiver.

You may ask me, if payment network is centralized or decentralized, what is the benefit for me in doing transactions?

Yes you have a benefit. You will be doing the transaction very fast in a decentralized payment network.

How my transaction is fast in decentralized payment network?

To transfer money to anyone in the bank you will be initiating the transaction. Then transaction will be transferred to the bank server and bank server in turn will transfer the transaction to the receiver. Here in every transaction your bank server is involved. Consider huge transaction in a day. Every transaction will take some time to process by the bank server. So It is possible for a queue under the bank server. So you may have to wait until bank server process it. But in decentralized network, there is no mediator. Payment is send directly from sender to receiver in bitcoin. So there is no queue and  your payment also very fast.

What is cryptocurrency?

Crypto currency is an medium through which currency is exchanged based on the cryptography technique. Bitcoin is the first cryptocurrency.

Bitcoin is a distributed cryptocurrency.

Have you heard about distributed ever? 

There are many thing like distributed database, distributed computing. Distributed is nothing where as data is stored in every computer and if any transaction occurs in single computer it will get synced with other computers.


Address is the basic thing in bitcoin transaction. Payments send or received only with respect to address.
Consider the bank account number. To send a payment in online transfer, you have to use the destination party account number. Here address is same as bank account number.
Okay Hope now I think something you have to ask me. Yeah got it. Then who will create the address for me?

Definitely I won’t be creating address for you. Lol.

Bitcoin wallet will create an address for you. Against that address you can send or receive payments from other bitcoin wallet.
One intelligent guy like you can ask, whether I can have multiple accounts in my bank. Whether I can have multiple accounts in bitcoin wallet.
Yes definitely you can have multiple account in bitcoin wallet. Just create another bitcoin address. Now you are lucky to have a multiple accounts.

Well, how bitcoin address will look like?

Whether it is an number as like bank account number or an text? It is just an pseudo random number. Address is generated randomly. It is an combination of numbers and letters. In technical term, it is alpha numeric.


Block chain is also called as a public ledger. It maintains all the transactions against the address of the bitcoin wallet.

Don’t think too much.

Hope every month you will be viewing the bank statement. It will contain all the transaction you have made. Block chain is much more similar to that, but it won’t contain your transaction alone, where as it will contain the transaction made by everyone in the bitcoin network. will show the live blockchain
Screenshot of live block chain take from web


Here I highlighted the latest transaction area. Where it contains the bitcoins transferred against the address.

Hey, my transaction is visible to all in the blockchain. Whether other people or my friends will get to know how much I spend or received through bitcoin?

No definitely not. Don’t worry about that. Only address is visible to others in the blockchain. Users private information like name will not be revealed to other users.
I think you are happy now! Happy spending.

How current balance is calculated?

As normal e-wallet system, balance is not stored based on the subscribers account in the bitcoin wallet.
Curious to know how balance is stored in the bitcoin wallet?  Let’s go.
Balance for the bitcoin wallet is calculated every time from the public ledger. Public ledger is nothing but the block chain in bitcoin terminology.

Block Chain

100 BTC
204 BTC
546 BTC
106 BTC
205 BTC
1000 BTC
50 BTC
2004  BTC
450 BTC
1500 BTC
So, consider Bob have made three transactions in bitcoin wallet.  Address of bob in bitcoin wallet is “Address_1”. When bob request for current balance then it is calculated from the above block chain trasaction table.
Here first it will fetch all record for Address_1 and it will calculate the balance.
=100 BTC +1000 BTC - 50 BTC
So now balance for bob in wallet is 1050 BTC

How to receive payments?

Receiving money through mobile

To receive the money,
  1. Install the bitcoin wallet application on your mobile or desktop
  2. Create an address in the bitcoin wallet application. This address is used to receive payments from other user.  Every new address can be created for receiving the payments
  3. Open the bitcoin wallet application in your mobile phone
  4. Display the QR code and ask the payee to scan your QR code.
    • What is QR code and what is contains?
      • QR stands for quick response code. It just contains the address of your wallet. When the payee scan your QR code, your address is read by the senders wallet application.
  5. Ask your payee to transfer the bitcoin from his wallet.
  6. When you initiate the transaction, bitcoin wallet application will store your transaction in the blockchain. This process is called mining or miners.
  7. All the transaction initiated by the bitcoin will be stored in the blockchain.
  8. Now the amount can be received from the payee.
  9. This works same when you want to pay something to others.

receive payments on bitcoin

Transactions and elements involved in the transaction

One interesting thing about transaction in bitcoin is , transaction made are made. They cannot be reversed back. Oh my god. Be careful while initiating any transaction in  the bitcoin.

There are three key elements is involved in the bitcoin transaction

1.       FROM ADDRESS: Address of the sender
2.       TO ADDRESS: address of one who receives the bitcoin
3.       Amount: Unit of bitcoin that need to be transferred.

Any fees required for transaction?

No fees are required to purchase the bitcoin.
Sometime it will be charged but they will charge rarely. I am sure, they will not charge like your traditional bank.

What about Privacy?

All transaction are visible to all in the block chain.
But the user identity against the transaction is not shown to all. So you are safe.

Symbol used to represent the bitcoin:

Symbol used to represent the bitcoin is BTC, XBT

Smallest units of bitcoin

As like cents in dollar, and coins in rupee, whether bitcoin can be split in to smaller segments?
Yes you can split.
Satoshi is the smallest one. It is one hundred millionth of single bitcoin.
Value of satoshi is 0.00000001 BTC.
Hold on, some were we heard this name satoshi in this article. I think you got it. Satoshi is one who created the bitcoin software.

Currently it can be split in to eight smaller parts.

Other smaller units and names of the bitcoin

0.01 BTC
1 cBTC = 1 centibitcoin
0.001 BTC
mBTC = 1 millibitcoin
0.000 001 BTC
1 microbitcoin

Why use bitcoin?

1.       Transactions are faster. Even international transfers are very faster
2.       Transaction charges are minimal in bitcoin when compared to the normal online bank transfers.
3.       You can use the bitcoin for worldwide payments.
4.       Payments can be made or received through bitcoin as 24*7. Even on holidays bitcoin will work. This helps many people to transfer their payments in emergency period.
5.       There is no limit on maximum or minimum for transfer in bitcoin. This is most interesting feature because many banks will restrict some limit on daily payments
6.       International funds transfer is very simple as national fund transfer with less transaction charge.

How it works securely?

Bitcoin use two keys such as private key and public key.

What is private key and public key?

Private key : It is key generated by the bitcoin wallet application.

Since it is mentioned as private key shall I want to keep it secret? Exactly you have to keep it secret and you should not reveal this private key to anyone. It is like your bank password. Typically your bank password is choosen by you whereas private key is automatically generated.

Public key: This key was also generated by the wallet.

You no need to worry about this key. Since this is a public key you can reveal this to anyone.
What keys are required to transfer?

Both private key and public key is required for initiating any transaction in wallet.
When you want to send money through bitcoin, you should sign digitally based on your pubic key and private key.  This is called as digital signing. once you signed bitcoin will create a certificate to authorize that this is initiated by you. Without private key bitcoins cannot be spend or used.

Bitcoin internally uses the cryptograph technique to make the payments secure and safe.
Be careful when you forget your private key you cannot get back the bitcoin. Keep your private key safe and secure. Private key is your wallet. Like wallet, once it is lost, we cannot get back the money.

All transaction is public in the bitcoin network.

I think you may worry that, whether my transactions will be shown to all.
Don’t worry. Only transactions are public in the payment network. But user identity associated with that transaction is not revealed to public.

Whether bitcoin can be stolen?

Yes it can be stolen. Don’t be panic. It can only be stolen when the private key is accessed by the others. Once private keys of bitcoin wallet is stolen by the theft, then there is an possibility that they can use their bitcoin in the online transactions

So, I think your worry could be how to keep private key safe.

1.        Just take the regular backup of the bitcoin wallet. It will help you when you lost your private key.
2.       Multisign option service is provided by the bitcoin.
What is multisign service?
Instead of single people digitally signing to initiate the transaction, many people  should sign to send or receive the payment. This many people can be business partners or your secondary device.
3.       You can use the paper wallet bitcoin option. paper wallet bitcoin will print all the bitcoins in the form of paper. Now finally it is like a paper money.

Money paid are paid forever:

Transaction initiated by bitcoin cannot be reverted back. once payment made are made.
There is no way to revert back the transaction in bitcoin. No option for refund in the bitcoin. Only way to refund is the one who received the payment has to sent it back to you. So be careful while sending the money.

Where to buy?

It can be purchased in the bitcoin exchanges.
Listed some the wallets, choose the any one on of the following for bitcoin transactions.

Android Application wallet

1.       Green Address
2.       Copay
3.       Bitcoin Wallet
4.       Bither
5.       Mycelium
6.       Coinomi

IOS Application wallet

1.       Green Address
2.       Bither
3.       Airbitz

Windows operating system wallet

1.       Bitcoin core
2.       Bitgo
3.       Bither
4.       Copay
5.       Green Address
6.       mSIGNA

Hardware wallet

1.       Keepkey
2.       Ledger Nano
3.       Trezor

Paper wallets

Many sites providing the paper wallet.  Here private keys are not stored digitally instead it is provided in the paper. Paper wallet will save you from the hardware crash, cyber attack and hackers. Disadvantage of the paper wallet is when you lost the paper wallet you cannot get back the bitcoins again.

Where can I buy the paper wallet?
            No need to run for shop to buy the paper wallet. Some online sites are providing the option to create the paper wallet.

How to print the paper wallet?
Do I need any special machine to print the paper wallet?
Oh no, you don’t need any special machine to print the paper wallet. If you have printer, that is more than enough.

Keep the printed paper safe.

What happens if you lost your paper wallet?

I am so sorry, you will be loose your bicoins.
Once after creation of paper bitcoin wallet, you can just take printout and store them safely in your home.

Can I keep the units for longer time?

It is not advised to keep the money for long time in wallet. This is because, based on the market price of the bitcoin will increase or decrease. So it is highly not recommended to keep the money in wallet. When you receive payments via bitcoin, then transfer in to local currency and keep it.

Litecoin vs bitcoin

Bitcoin was developed and released as open source.
What is opensource?
Open source is an software terminology where as source code of the software will be open to all. This helps the other developer to modify and release the new software.
As I said one developer have taken the source code of the bitcoin and modified it and released as brand new “Litecoin”.
Litecoin is almost similar to bitcoin. To be clearer, it is like two cars. One car is Honda and another car is Hyundai. Both cars are used to travel on road. But each one has their own unique features. Likewise Litecoin and bitcoin are two different brands with their own unique features.

Where bitcoin is produced ?

      It is produced through the process of mining.

What is mining?

It is process of producing the new bitcoins in the payment network.
Miners usually produce the bitcoin and this process is called as mining.

Roles and Responsibilities of miners
1.       Producing new coins in the payment network
2.       Securing the transactions in the network
3.       Miners make the network stable and secure.

Is it legal?

It is purely depends on who you are, where are using it, which country you reside, purpose using it for.
Of course many law enforcement agencies are in progress to make it legal. But they were concerned about the following problems in their approval

a.       It is decentralized, so government don’t have control on the money.
b.       No control on who produces bitcoin

These are things which act as bottleneck to make it as legal.

For india, Reserve bank of india is validating for use of virtual currency. Reserve bank of india is in progress for taxation of virtual currency.

Advantage over paper money

1.       Paper money will occupy the physical space, it won’t take the physical space. So you can store more money with less physical space.
2.       When physical money is lost, it is lost forever. We cannot do anything to retrieve the money back. Here you take backup of your wallet. Not only single backup, you can take more and more backup of the wallet. So even when one backup is lost, you can retrieve the money.
3.       No need to carry your physical wallet everywhere you go.
4.       You can give the exact money to the receiver. No need to worry about give the exact change.

who controls the bitcoin?

Bitcoin is controlled by software running on multiple computers. No government, organization or even an individual is involved in controlling the bitcoin.

whether bitcoin can be printed?

Bitcoin cannot be printed as normal money since it is the digital currency or virtual currency.
It is also called as electronic cash, virtual currency, electronic currency or cryptocurrency.
Oh wait! Of course, it can be printed. Not as money. It can be printed as bitcoin paper wallet. It will be explained later in this article.

Third party payment processor

Are you running a website and selling something to customers. You can charge your customers for the product you were selling and you can get the charge for the product as bitcoins.
So how to charge the customers as bitcoins?
There are several third party payment processors which helps to collect payments.
Third party payment processors include CoinBase, BitPay, BIPS etc.,

Who is inventor of bitcoin?

Satoshi Nakamato is the inventor of bitcoin.
            Satoshi Nakamato published the paper on the May 2008 and released the software on Jan 2009. Satoshi Nakamato released the software as open source code.

Any mistakes and improvements for this post are welcome...