Thursday, January 23, 2014

Pointers: Null Pointer.

C language
C language
Hope you have read the previous post on Dangling pointer ( if not click here.). Here I am going to introduce one more pointers: Null Pointer.

Null Pointer:

The simple meaning of null pointer is, the pointer which is pointing to null value i.e we can say pointer which is pointing to nothing. Null pointer identically points to the base address of memory segment.
Examples of NULL pointer:

1. int *ptr=(char *)0;
2. float *ptr=(float *)0;
3. char *ptr=(char *)0;
4. double *ptr=(double *)0;
5. char *ptr=’\0’;
6. int *ptr=NULL;

We cannot copy any thing in the NULL pointer.

Example:

#include
 <stdio.h>
#include <string.h>
int main(){

char *ptr=NULL;
    strcpy(ptr,
"newtechshow.blogspot.com");
printf("%s",ptrr);


return 0;
}

This program will give output : null (or segment fault).

Application

  • At the end of the linked list, last node's pointer is always null. so that the linked list terminates there otherwise it goes to infinite if last pointer points to garbage values.
You can  think more applications and comment here.

Monday, January 20, 2014

How to remove hidden virus from pen drive.

(Note: I got this trick by email, remove important data before doing this.)

If your Pen Drive is infected with any of the following viruses:

* Autorun.inf
* new folder.exe
* Iexplorer.vbs
* Bha.vbs
* nfo.exe
* New_Folder.exe
* ravmon.exe
* RVHost.exe or any other files with extension.

Actually this viruses are hidden and can't be seen even after you enable show hidden folders.
Following simple dos command will change the attributes of these files ,there after you can remove it
by pressing delete key.

Follow these steps:
Step1.:Type cmd in Run
Step2.: Switch to the drive on which pen drive is connected(like C:\> h: enter)
Step3.: type exactly as
attrib -s -h *.* /s /d
and hit enter(don't forget spaces).


Now you can see hidden virus files and
you can delete them.

You may also like :=> problem: All exe files are opening in vlc

Sunday, January 19, 2014

C Pointers - Dangling Pointer Problem

I found that many of under graduate students facing difficulties with pointers. In interviews generally the most of questions come from Pointers Only. Don't afraid of it . Make the basics clear by reading ANSI C or LET US C Or Try from some good video lectures. Here I am introducing some important aspects of pointers.



C pointers


Dangling Pointer Problem:

If any pointer is pointing to the memory address of a variable , but after sometime that variable is deleted from the memory. Now the pointer is still there and pointing to that particular location. Such pointer is known as dangling pointer and this problem is called dangling pointer problem.

So initially,

After the deletion of variable,
So now ptr is now become dangling pointer which is pointing to some garbage value.

Consider the following program:

#include<stdio.h>


int *foo();
void main(){

int *ptr;
ptr=foo();
printf("%d",*ptr);

}
int *foo(){

int x=25;
++x;

return &x;
}

Output of this programme:Garbage value
Here, Initially the pointer ptr is pointing the variable X of the function foo. The scope of X is only inside the function. So after returning address of X variable X became dead and pointer is still pointing ptr is still pointing to that location. 

The solution of this problem is , Make the variable X static so that it will not become dead or declare X as global variable then no such problem will arise.

You may Also like- Why C treats array parameters as pointers?


Tuesday, January 14, 2014

Basics Of Cloud Computing.

Yahh!! Each and every technical people is talking about cloud computing, but you ask them what is actually cloud computing? then 70% of them can't even give some basic definitions. So lets try.

Cloud Computing simply means Internet computing. The internet is commonly visualized as clouds, hence the cloud computing for computation done through internet.


Cloud Computing
Cloud Computing

What is the cloud?

The cloud is where you put all your data, all your files and even your software
so you can access it all from any computer or device, anywhere, anytime. 

Characteristics:

  • Cloud computing is cost effective. Here, cost is greatly reduced as initial expense and recurring expenses are much lower than the traditional computing.
  •  Maintenance cost is reduced as a third party maintains everything from running the cloud to storing data.
  • Cloud is characterized by features such as platform, location and device independence, which makes it easily adoptable for all size of business.
  • Another most important characteristic of cloud is scalability, which is achieved through server visualization.

Service Models:

Once a cloud is established, how its cloud computing services are deployed in terms of business model can differ depending on their requirement. The primarily service model being deployed are commonly known as:

Software as a Service:
SaaS
is a software model. It is provided to client through an online service. Clint  does not have to install or maintain SaaS application. Software is running on a provider’s cloud infrastructure and a user can access it via web browser. With SaaS, vendor makes the required software available to a business on subscription basis, and charges are based on the product usage. SaaS model can save the companies   expenses on buying hardware and software and it removes the maintenance costs.
·     Platform as a Service: 
PaaS is a platform and tools  provided to client to develop applications in a cloud environment.  The provider is responsible for maintenance and control of the underlying cloud infrastructure including network, servers, and operating systems. PaaS services provide a great deal of flexibility allowing companies to build PaaS environments on demand with no capital expenditures.

 
Infrastructure as a Service:
With IaaS, a company can rent fundamental computing resources for deploying and running applications or storing data. It enables companies to deliver applications more efficiently by removing the complexities involved with managing their own infrastructure. IaaS enables fast deployment of applications, and improves the ability of IT services by instantly adding computing processing power and storage capacity when needed.




Isn’t cloud computing just the internet?

You use the internet to connect your device to the cloud, but the internet is just the connection – the cloud is where your data lives.

Isn’t it possible to lose your data in the cloud?

Your data is actually much safer in the cloud than on your computer. Your computer can be stolen or corrupted quite easily, but cloud companies spend millions on systems and experts to protect your data.


You may also like to Read: Basics Of Cryptography.

Friday, January 10, 2014

Difference between “int main()” and “int main(void)” in C/C++?

Generally we don't concern anything above main() or main(void). both look similar to us but there is a difference between both and it is useful too.
C language


Consider the following two definitions of main().
int main()
{
   /*  */
   return 0;
}
and
int main(void)
{
   /*  */
   return 0;
}
What is the difference?

In C++, there is no difference, both are same.

Both definitions work in C also, but the second definition with void is considered technically better as it clearly specifies that main can only be called without any parameter.

In C, if a function signature doesn’t specify any argument, it means that the function can be called with any number of parameters or without any parameters. For example, try to compile and run following two C programs (remember to save your files as .c). Note the difference between two signatures of fun().
// Program 1 (Compiles and runs fine in C, but not in C++)
void fun() {  }
int main(void)
{
    fun(10, "GfG", "GQ");
    return 0;
}

The above program compiles and runs fine , but the following program fails in compilation
// Program 2 (Fails in compilation in both C and C++)
void fun(void) {  }
int main(void)
{
    fun(10, "GfG", "GQ");
    return 0;
}
Unlike C, in C++, both of the above programs fails in compilation. In C++, both fun() and fun(void) are same.

This is important to know about scanf()- SCANF() - Some important features.

Saturday, January 4, 2014

Algorithms Types Based On Their Working Nature.

Mainly there are three types based on the working nature of the Algorithms. Every student who learns algorithm should be familiar with the taxonomy. The types are :
  1. Las Vegas Algorithms
  2. Randomized Algorithms
  3. Monte Carlo Algorithms 
Algorithm
Algorithms

1. Las Vegas Algorithms:
->An algorithm whose  running time may change but always gives correct output is called as Las Vegas Algorithm.
for example : Randomized Quicksort.

2. Randomized Algorithms:

->which employs a degree of randomness. We can characterised acceptable algorithm based on bound the probability that any "bad" thing may happen. So running time and output is random.

3, Monte Carlo Algorithms:

->Actually it's a type of randomized algorithm whose running time can be determined but output may be incorrect in certain probabilities.