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.


Friday, December 27, 2013

C program to print 'xay' in place of every 'a' in a string.

This question was asked in one the technical interview( Under graduate level). This is kind of application for  'replace' feature. You can make it more accurate by putting more constraints.

Ans :

#include<stdio.h>
int main()
{
int i=0;
char str[100],x ='x',y='y' ;
printf("Enter the string\n:");
gets(str);
while(str[i]!='\0')
{
if(str[i]=='a')
{
printf("%c ",x);
printf("%c ",str[i++] );
printf("%c ",y);
}
else
{
printf("%c ",str[i++] );
}
}
return 0;

Tuesday, December 24, 2013

How to deallocate dynamically allocate memory without using “free()” function.

NOTE: this is actually puzzle type question nobody  use it realloc() function to free the memory. But I heard, in many interviews this question had been asked.

Standard library function realloc() can be used to deallocate previously allocated memory. Below is function declaration of “realloc()” from “stdlib.h

void *realloc(void *ptr, size_t size);
 
If “size” is zero, then call to realloc is equivalent to “free(ptr)”. And if “ptr” is NULL and size is non-zero then call to realloc is equivalent to “malloc(size)”.

Let us check with simple example.

/* code with memory leak */
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
    int *ptr = (int*)malloc(10);
 
    return 0;
}
 
Check the leak summary with valgrind tool. It shows memory leak of 10 bytes, which is highlighed in red colour.

 valgrind –leak-check=full ./free
  ==1238== LEAK SUMMARY:
  ==1238==    definitely lost: 10 bytes in 1 blocks.
  ==1238==      possibly lost: 0 bytes in 0 blocks.
  ==1238==    still reachable: 0 bytes in 0 blocks.
  ==1238==         suppressed: 0 bytes in 0 blocks.

Let us modify the above code.
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
    int *ptr = (int*) malloc(10);
 
    /* we are calling realloc with size = 0 */
    realloc(ptr, 0);
    
 
    return 0;
}
 
Check the valgrind’s output. It shows no memory leaks are possible, highlighted in red color.
  >valgrind –leak-check=full ./a.out
  ==1435== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 11 from 1)
  ==1435== malloc/free: in use at exit: 0 bytes in 0 blocks.
  ==1435== malloc/free: 1 allocs, 1 frees, 10 bytes allocated.
  ==1435== For counts of detected errors, rerun with: -v
  ==1435== All heap blocks were freed — no leaks are possible.
  

Saturday, December 21, 2013

SCANF() - Some important features.

scanf()
The scanf()is very powerful function. We can use it to scan the input but we can add something in it's arguments and make it very powerful function.

Assume that we have one variable : a[100];

To read a string:
             scanf("%[^\n]\n", a);
            // it means read until you meet '\n', then trash that '\n'
 
 
To read till a coma:
             scanf("%[^,]", a);
            // this one doesn't trash the coma

             scanf("%[^,],",a);
           // this one trashes the coma
 
If you want to skip some input, use * sign after %. 
For example you want to read last name from "John Smith" :
          scanf("%s %s", temp, last_name);
         // typical answer, using 1 temporary variable

         scanf("%s", last_name);
         scanf("%s", last_name);
        // another answer, only use 1 variable, but calls scanf twice

          scanf("%*s %s", last);
        // best answer, because you don't need extra temporary variable nor 
           calling scanf twice 
 
 

To know, Why should u not use turbo c++ ? click here

 
C language
  

Saturday, December 14, 2013

Why should u not use turbo c++ ?

I have seen that in many under graduate collages turbo c++ is still used.  But now a days it is an outdated IDE.  Please, do not use it. It is totally useless.

Draw backs of Turbo C++
Turbo C++
There are many recent IDEs available which has great features and no bugs like GCC or Eclipse C/C++. Now a days GCC is treated as standard compiler.

some of drawbacks of Turbo C++:
  • Debugging is not as efficient as they are in other IDEs
  • It is not conformed with the standards that are laid down
  • It does not support modern casts, only C-Style casts.
  • I doubt if it may not goes well with 3rd party libraries! eg database or graphics libraries
There are other run time drawbacks also. So it is preferable to not use turbo C++ .




Friday, November 29, 2013

Why C treats array parameters as pointers?

In C we can see that array parameters are generally treated as pointers. See the following definitions of two functions:

void function1(int arr[])
{
  /* Silly but valid. Just changes the local pointer */
  arr = NULL;
}
void function2(int *arr)
{
  /* ditto */
  arr = NULL;
}
Array parameters are treated as pointers because of efficiency. Mostly when we pass array to the function then we mostly want to deal with same array. So no need to copy whole array to the function, just reference is sufficient. It is inefficient to copy same array as memory and time perspective .
C language