Answered Questions

  • A program in C using Void Pointer

    {geshibot language="c"}#include #include int main() { int a=10; void *p; p=&a; clrscr(); printf("%u",*p); getch(); return; }{/geshibot} I know that this program is wrong as error is shown on compiling it. Anyone please provide a simple program using Void pointer in C. Thanks in advance :)

    Ashok Kumar Orupalli

    • Sep 3rd, 2012

    You have to typecast void pointer to int as *(int*)p;

    Code
    1. #include<stdio.h>
    2. #include<conio.h>
    3. int main()
    4. {
    5.  int a=10;
    6.  void *p;
    7.  p=&a;
    8.  clrscr();
    9.  printf("%u",*(int*)p);
    10.  getch();
    11.  return 0;
    12. }

    Sereche

    • Jul 9th, 2012

    Your error is on line 9, where youve attempted to dereference a pointer to void (the expression *p). You can only dereference typed pointers. The solution you are probably looking for would be to repl...

  • Printing Linked List In a Reverse Order Using Head Pointer

    How to write a program to print a linked list in reverse order by using only one head pointer[without moving the head pointer].

    Sereche

    • Jul 9th, 2012

    The fastest way to do this is to traverse the linked list forward once, saving the value at each node (or a pointer to the node) in a backwards-traversable data structure. If you know the size of the ...

  • C Coding question on running time program

    /*assume contents are sorted*/Public static intbinarySearch(int x,int a[]){int low=0; 0(1)int high=a.length-1; 0(1)int mid; 0(1)while(low>x;while(x!=99){n++; 0(1)sum+=x; 0( n/x)cin>>x;}mean - sum/n;what is the running time?Please help me understand it. The websites are not that helpful to me. Please. Please if you're not that busy can you please answer it with explanations?:) :) :) THANK YOU!!

    Sereche

    • Jul 9th, 2012

    This seems to be a question about time complexity / big-O notation. Time complexity basically tells you how the program running time scales, as a function of one of the variables of input (in most cas...

  • Marbles and Floors

    You have a 100-story building and a couple of marbles. You must identify thelowest floor for which a marble will break if you drop it from this floor. How fastcan you find this floor if you are given an infinite supply of marbles? What if youhave only two marbles?

    Tyler

    • May 20th, 2015

    Start at floor 10. If the marble breaks start at 1. If it Doesnt go to 20: repeat for 11-19, and Repeat the process for 30,40,... to 100. Max amount of Drops will be 19: at 91. Up all the way to 100(10 drops) and 9 floors down(9 drops)

    lily

    • Apr 15th, 2015

    With 2 marbles: Go to floor 50. If the marble breaks, go to floor 1 then floor 2 and so on up to floor 49 or until your marble breaks. Then the solution is the previous floor. If the marble doe...

  • Read Heterogenous Linklist

    While creating a heterogenous linklist we know that we use void pointer. But when we need to read the information, How will you do it? How will you figure out to what datatype does the data belong to?

    Sereche

    • Jul 9th, 2012

    Some kind of information regarding the type is obviously required. If there is no way of determining it from the context (i.e., the previous node in the list somehow specifies the type), it must be st...