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 :

int main()
int i=0;
char str[100],x ='x',y='y' ;
printf("Enter the string\n:");
printf("%c ",x);
printf("%c ",str[i++] );
printf("%c ",y);
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.

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

           // 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

Wednesday, November 27, 2013

Voice Search On Google



Search by speaking.

- You can now say things like "pictures of …" or "where is …?"
- Fixed browser button in latest versions of Chrome.

Voice Search provides a method to search by speaking. For example,
just click on the microphone and say "kittens" to search for kittens. 
If you specifically want pictures of kittens, say "google images 
Want to learn more about World War II? Say "wikipedia world war two".

Voice Search comes pre-loaded with the following default services: 
Google, Wikipedia, YouTube, Bing, Yahoo, DuckDuckGo and Wolfram|Alpha. 

You can also add your own user-defined search engines. 
It also integrates speech input buttons for text fields on all websites.

This extension requires a microphone, and it needs access to all 
 so it can add speech input buttons to every text field.

How to Get it on your PC

>Download Google's Chrome browser.
>you need, because it turns out Voice Search is built right in. 
>Just head to, 
>then click the little microphone on the right side of 
>the search field. (Needless to say, this will work only if your PC has
 a microphone. 
Most laptops do; most desktops don't, unless you have a 

The feature is also available in Google Maps,
 though it doesn't extend to other Google properties like Calendar, 
Gmail, and YouTube.

Sunday, November 17, 2013



We use to go cyber cafe or any other place and open facebook or from friend's mobile  and  sometimes we forgot to log out but now  don't need to be worry about it,there is a option to log out your account from every computer.....

follow the steps...

1. log in your account (from anywhere)
2. go to account setting
3. click on account security
4. and see there details...its shows
Last Accessed:
Device Type:
"see the image"
(if only these 3 things are shown there, then you are safe)

if there is an option to "end activity"that means your account is opened somewhere else also...
click "end activity" and you`ll be logged out from other computer

Sunday, November 10, 2013

Different Technologies & Their Founders

If any mistake, inform me ...plz...

1. Google: Larry Page & Sergey Brin
2. Facebook: Mark Zuckerberg
3. Yahoo: David Filo & Jerry Yang
4. Twitter: Jack Dorsey & Dick Costolo
5. Internet: Tim Berners Lee
6. Linkdin: Reid Hoffman, Allen Blue & Koonstantin
7. Email: Shiva Ayyadurai
8. Gtalk: Richard Wah kan
9. Whats up: Laurel Kirtz
10. Hotmail: Sabeer Bhatia
11. Orkut: Buyukkokten
12. Wikipedia: Jimmy Wales
13. You tube: Steve Chen, Chad Hurley & Jawed Karim
14. Rediffmail: Ajit Balakrishnan
15. Nimbuzz: Martin Smink & EvertJaap Lugt
16. Myspace: Chris Dewolfe & TomAnderson
17. Ibibo: Ashish Kashyap
18. OLX: Alec Oxenford & Fabrice Grinda
19. Skype: Niklas Zennstrom,JanusFriis & Reid Hoffman
20. Opera: Jon Stephenson von Tetzchner & Geir lvarsoy
21. Mozilla Firefox: Dave Hyatt & Blake Ross
22. Blogger: Evan Willams

Thursday, November 7, 2013


-> Core i3:

* Entry level processor.
* 2-4 Cores
* 4 Threads
* Hyper-Threading ­ (efficient use of processor resources)
* 3-4 MB Cache
* 32 nm Silicon (less heat and energy)

-> Core i5:

* Mid range processor.
* 2-4 Cores
* 4 Threads
* Turbo Mode (turn off core if not used)
* Hyper-Threading ­ (efficient use of processor resources)
* 3-8 MB Cache
* 32-45 nm Silicon (less heat and energy)

-> Core i7:

* High end processor.
* 4 Cores
* 8 Threads
* Turbo Mode (turn off core if not used)
* Hyper-Threading ­ (efficient use of processor resources)
* 4-8 MB Cache
* 32-45 nm Silicon (less heat and energy)

Tuesday, November 5, 2013

C program to print a semicolon without using a semicolon anywhere in the code.

Generally when use printf("") statement we have to use semicolon at the end.
If we want to print a semicolon, we use the statement: printf(";" );
In above statement, we are using two semicolons . The task of printing a semicolon without using semicolon anywhere in the code can be accomplish ed by using the ascii value of';'which is equal to 59.
Program: Program to print a semicolon without using semicolon in the code.

int main(void) {
//prints the character with ascii value 59, i.e., semicolon
if (printf("% c\n", 59)){
//prints semicolon
return 0;

Tuesday, October 29, 2013

C programs that print hello word without using semicolon

It is easy to run a program that prints hello world without using a semicolon. Here some solutions are given. try new if possible.
<Yahh..!! this is for B.Tech guys..!!>

Solution: 1
void main(){
    if(printf("Hello world")){
Solution: 2
void main(){
    while(!printf("Hello world")){
Solution: 3
void main(){
    switch(printf("Hello world")){

Tuesday, September 24, 2013

How to find median in order of log n ?

Median in an infinite series of integers

Solution: Use 2 heaps: One MaxHeap and one MinHeap.

1) MaxHeap contains the smallest half of the received integers
2) MinHeap contains the largest half of the received integers

The integers in MaxHeap are always less than or equal to the integers in MinHeap. Also, the number of elements in MaxHeap is either equal to or 1 more than the number of elements in the MinHeap.

In the stream if we get 2n elements (at any point of time), MaxHeap and MinHeap will both contain equal number of elements (in this case, n elements in each heap).

Otherwise, if we have received 2n+1 elements, MaxHeap will contain n+1 and MinHeap n.

Let us find the Median: If we have 2n+1 elements (odd), the Median of received elements will be the largest element in the MaxHeap (nothing but the root of MaxHeap). Otherwise, the Median of received elements will be the average of largest element in the MaxHeap (nothing but the root of MaxHeap) and
minimum element in the MinHeap (nothing but the root of MinHeap). This can be calculated in O(1).

Inserting an element in heaps can be done O(logn). Note that, any heap containing n+1 elements might need one delete operation (and insertion to other heap) as well.

Total Time Complexity: O(logn).

Suppose we have sequence like : 1,9,2,0 then construction of heaps:

Insert 1: Insert to MaxHeap.

MaxHeap: {1}, MinHeap:{}

Insert 9: Insert to MinHeap. Since 9 is greater that 1 and MinHeap maintains the maximum elements.
MaxHeap: {1}, MinHeap:{9}

Insert 2: Insert MinHeap. Since 2 is less than all elements of MinHeap.
MaxHeap: {1,2}, MinHeap:{9}

Insert 0: Since MaxHeap already contains more than half; we have to delete the max element from MaxHeap and insert it to MinHeap. So, we have to remove 2 and insert into MinHeap. With that it becomes:
MaxHeap: {1}, MinHeap:{2,9}
Now, insert 0 to MaxHeap.

Via Narasimha Karumanchi Sir :

Saturday, September 7, 2013

Monday, September 2, 2013

stack programme using structure in C

#define structsize 10
struct stack
    int top;
    int item[structsize];
void push(struct stack *ps)
    int element;
    printf("\npush an element:");



void pop(struct stack *ps)
    int element;
    printf("underflow flow\n");
    printf("\npoped element is :%d",element);

void display(struct stack *ps)
    int i;
    printf("\ncurrent stack is:\n");
        printf("\n %d",ps->item[i]);
int main()
int arr[50],ch;
struct stack s;;
printf("\n\nEnter \n1: push\n2:pop\n3:print stack \n4:exit \n\n enter choice:");
        case 1:push(&s);
        case 2:pop(&s);
        case 3:display(&s);


return 0;

Sunday, September 1, 2013

How to find execution time of program in C??

We always eager to know that how much time my program takes to give me output. As a good programmer you always worry about the time complexity. If you print your execution time along with output then you can check your execution time for different test cases. It's really exiting.

int main()
clock_t begin, end;
begin = clock();
double time_spent;

     write your code

end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("\n execution time for sorting: %f seconds ",time_spent);

return 0;


Thursday, August 15, 2013


What is a motherboard ??

A motherboard (also known as the mainboard, system board, planar board or logic board) is the main PCB found in computers and other expandable systems. It holds many of the crucial electronic components of the system, such as the CPU, memory, and processor.

The function of the computer motherboard is to act as the main circuit board that connects and communicates to all the devices and components attached. The motherboard also facilitates the communication of devices with each other. Motherboards are designed around the type of central processing unit (CPU) that will be installed. Because motherboards act as the base for all other computer components, the number of PCI slots, USB headers, memory slots, SATA headers, and other slots should be checked ahead of time before building a personal computer.

A typical desktop computer has its microprocessor, main memory, and other essential components connected to the motherboard. Other components such as external storage, controllers for video display and sound, and peripheral devices may be attached to the motherboard as plug-in cards or via cables, in modern computers it is increasingly common to integrate some of these peripherals into the motherboard itself.

An important component of a motherboard is the microprocessor's supporting chipset, which provides the supporting interfaces between the CPU and the various buses and external components. This chipset determines, to an extent, the features and capabilities of the motherboard.

What are the reasons for mother board failure? 

  1. First and most common reason is heat. Keep cabinet ventilated to prevent high temperature inside the box.
  2. Check your Fan speed, if it is not normal then hurry up!! repair it.
  3. Dust also cause problems. clean your pc regularly and prevent it from the dust environment.
  4. Use static power supply, put power controller to prevent your pc from unregulated ac power supply.
  5. Do not install the software that cause damage your system. Use only trusted and light software if possible. 
  6. Do not play the games which require high processing power ( before installation, see whether it is suitable to your configuration or not.)   
  7. Keep your pc free from viruses and worms , they put extra overload on processor.
  8. When everything is going well, don't ever upgrade BIOS without right upgrade files.
  9. Do not play with BIOS and RAM if you don't know properly about it.

    Thursday, August 1, 2013

    How to terminate processes in ubuntu??

    In windows we can easily terminate the process by
    • ctrl+alt+del 
    • right click on program name
    • go to process
    • end process.
    but in Linux , it is not that much easy, u have to follow the terminal steps:

    example: to close firefox process.
    • Open terminal (ctrl+alt+t)
    • type command : ps auxwww | grep firefox
    • u will get some table , in which u find process IDs
    • type command : kill 2348 (note: 2384 is process id, it is different each time )
    Kill process is very useful when your program is not responding.

    Tuesday, July 30, 2013

    All android versions and their names

    Android 1.5 Cup Cake
    •  Android 1.5 =  Cupcake
    •  Android 1.6 Donut
    •  Android 2.0/2.1 Eclair
    •  Android 2.2 = Froyo
    •  Android 2.3 = Gingerbread
    •  Android 3.0/3.1/3.2 = Honeycomb
    •  Android 4.0 = Ice Cream Sandwich
    •  Android 4.1/4.2/4.3 = Jelly Bean
    •  Android 5.0 = Lime Pie    

    Android 1.5 Cup Cake

    Sunday, July 28, 2013

    To print indian map in "c" langauge

    #include<conio.h> //for windows only
    void main()
    int a,b,c;
    for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
    TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
    T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
    Hq!WFs XDt!" [b+++21]; )

    for(; a-- > 64 ; )
    putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
    India map

    Thursday, July 25, 2013

    Problem : Firefox is responding very late

    many of you might facing a problem with  " Firefox web browser" that it responding too late, even input from keyword is also not taking well etc...

    I got one solution, after doing this my browser responding nicely.

    • Go to tools->add-ones->Extention
    • Remove all your video and Flash plug-ins ..
    • restart the Firefox
    now enjoy original fast firefox...

    Tuesday, July 23, 2013

    Don't use Free() more than once for same pointer

    To use Free() more than once cause a "FATAL ERROR" .
    "FATAL ERROR" cause CRASH the program,
    and because of which we get a segmentation fault as error...

    sometime it also make problem when we are doing program in group. one member frees the pointer while actually another fellow is using same pointer.
    so never try to use Free() more than once for same pointer.  

    Wednesday, July 17, 2013

    How to install java in ubuntu??

    • First start your terminal ( if not found on desk top try shortcut key ctrl+alt+T)
    • make sure you are connected to the internet.
    • update your Ubuntu by the command : sudo apt-get update
    • then install java (jdk and jre) by the command :
      sudo apt-get install openjdk-6-jdk openjdk-6-jre
    • To check if java has been installed in your system, type the following command:

      javac -version

    Monday, April 22, 2013

    problem: All exe files are opening in vlc

    When you try to open any exe file or say shortcuts then it opens in vlc media player that is horrible. I have found some solutions try them .
    1.  click here  and fix it.
      If you are unable to open Internet Explorer to access the link, hit the Windows key plus r on your keyboard and copy and paste the below command in the Open Box (this assumes that W7 is installed on your C drive):

      rundll32 shell32.dll, ShellExec_RunDLL "C:\Program Files\Internet Explorer\iexplore.exe"
    2. download and install
      Fix .exe : click here to download
      install it . this works many times.

    Tuesday, April 16, 2013

    why you not recieving any sms from internet sms website???

    Aren't you receiving any SMS from various online free daily sms sender or is you phone no more has any notifications of new sms's, that is because of change in the TRAI rule, most of them are not receiving messages from the usual sources where they used to get. The rule was passed to protect consumer privacy from SMS spammers.
    You must be shocked to see such kind of errors even while sending the message from sites like Way2sms, 160by2 or any other online free sms sending sites or even from Google Labs. Error: DND Number, Cant send message.
    Way2sms error: Submission Failed. Mobile Number is in DND
    To receive SMS from Google Channel Labs/ Way2sms/ 160by2 without any problem, you have to de-register from National Do Not Call Registry(NDNC) by sending an SMS from your mobile

    STOP DND to 1909. 
    Which is a toll free number and you would not be charged for sending this message.

    In short it means you have registered for Do Not Call(DNC) earlier and now you are de-registering.

    Thursday, April 11, 2013

    Why bother to learn "C language" Today??

    Now a days there  are many superior languages are available like C++, java, C# etc, then why to learn C??? There are several reasons for this , as follows-
    1. I believe that nobody can learn such higher languages like C++,java,C# directly because it has things like classes, objects, polymorphism, Exception handling etc..we can learn this complicated components easily when we are comfortable with basics. So we can learn this basics easily with C.
    2. Major parts of popular Operating Systems like windows, linux ,UNIX are still written in C.
    3. Embedded Systems like Microwave ovens , washing Machines , digital cameras are getting smarter day by day. This smartness comes from OS and Smart Programs . These programs not have to only run fast but also have to run in limited amount of memory. No wonder that such C programs are written in C.
    4. In 3D computer games speed is essential component. So for fastness C language scores over other languages.
    5. At time one is required to very closely interact with hardware devices. Since C provides several language elements that makes this interaction feasible without compromising the performance.   


    Saturday, April 6, 2013



    is the study of mathematical techniques related to aspects of information security, such as confidentially or privacy ,data integrity and entity authentication. Cryptography is not only means of providing information security, but rather one set of techniques. Confidentially means keeping information secret from all but those who authorized to see it. Data integrity means ensuring information has not been altered by unauthorized or unknown means. Entity authentication means corroboration of the identify of an entity.

    Definition of cryptography

     Cryptography is the study of mathematical techniques related to aspects of information security, such as confidentially or privacy, data integrity and entity authentication. Cryptography is not the only means of providing information security, but rather one set of techniques.


    Categories of cryptographic algorithm

    There are main two types of cryptographic algorithm.
    1: - Symmetric key
    2: - Asymmetric key

    Symmetric key

    1.  Sender and Receiver share a key.          
    2.  A secret piece of information used to encrypt or decrypt the message.
    3.  If a key is secret, than nobody other than sender or receiver can read the
    4.  If Alice and bank each has secret key, than they may send each other 
          private    message.
    5.  The task of privately choosing a key before communication, however can 
          be problematic.

    Asymmetric key

    1.  Solves the key exchange problem by defining an algorithm which uses     
          two keys, each of which can be use to encrypt the message.
    2.  If one is used to encrypt a message, another key must be used to 
          decrypt it.
    3  This makes it possible to receive secure message by simply publishing one
          key (public key) and keeping another secret (private key).
    4  Any one may encrypt a message using public key, but only the owner of
          the public key is able to read it.
    5  In this way Alice may send private message to owner of a key-pair (the      
          bank) by encrypting it using their public-key. Only bank can decrypt it.

    Goals of cryptography

    The main goals of cryptography are
    1: - Confidentially or privacy
    2: - Data integrity
    3: - Authentication
    4: - Non-repudiation


    Characteristics of a cryptographic algorithm

    The main characteristics of cryptographic algorithm are
    1: - Level of security
    2: - Performance
    3: - Ease of implementation