Tuesday, July 14, 2009

NEED URGENT HELP IN C programming?

PLS tell how to calculate days between dates using structure pointers in C

NEED URGENT HELP IN C programming?
/* difftime example */


#include %26lt;stdio.h%26gt;


#include %26lt;time.h%26gt;





int main ()


{


time_t start,end;


char szInput [256];


double dif;





time (%26amp;start);


printf ("Please, enter your name: ");


gets (szInput);


time (%26amp;end);


dif = difftime (end,start);


printf ("Hi %s.\n", szInput);


printf ("It took you %.2lf seconds to type your name.\n", dif );





return 0;


}
Reply:read in two dates.


from the earlier date, keep adding one day, until you reach the other date.


Look at how many days you had to add.


you got what you wanted ;)


Questions relatewd to c & java?

about pointers in c.


operators in java

Questions relatewd to c %26amp; java?
pointers are ref addresses


operators are symbols that rep a operation ie - is minus


hope this helps :)
Reply:http://www.pekiyi.150m.com


java and c language pages.
Reply:point it can store the other address of other object.
Reply:lol
Reply:Go to this site to get details of pointers in C.








http://www.cs.cf.ac.uk/Dave/C/node10.htm...


About pointers in C...?

i am confused between these two..





int *s,p=1;





s=%26amp;p;


s=p;





if s=%26amp;p points the address of p by s


how about s=p?


what is the difference between the two?

About pointers in C...?
s=%26amp;p


means you are assigning the address of the variable 'p' to the pointer variable 's'


and i think the second statement "s=p" will generate an error... coz you are trying to assign an int value to an int pointer.
Reply:So, think of a computer's memory as a long tape, and an address as a position on that tape. A pointer is simply an address contained in a variable that tells the computer to go to the position on the tape that's specified in the variable, got it? Now, by going %26amp;p, you're looking for where p is on that 'tape' so the computer can find it and change it's value later. When you store p into s, you're storing the contents of p into something that's supposed to only hold an address. So, when the computer tries to dereference the pointer, it ends up looking for this value that could be anywhere on the 'tape', but doesn't refer to anything specifically, which is very bad. The only time you'd see something like s=p is if both were pointers, and you want p to refer to whatever s was referring to in the first place.
Reply:s = p will store what's in p into s, in other words s will contain 1. This is of course NOT what s is meant to have in it, and any decent C compiler should produce at least a warning message about this


Assigning pointers in C++?

I do not understand the following code





V * v = new V;


v-%26gt;i=8;


System::Console::WriteLine(v-%26gt;i);





pin_ptr%26lt;V%26gt; mv = %26amp;*v; %26lt;--- what does %26amp;*v means?


mv-%26gt;i = 7;

Assigning pointers in C++?
It appears that you took this example right from the MSDN documentation. Basically what this code is doing is declaring a pointer to the structure 'V', then it is setting the integer member 'i' to the value of 8.





The pin_ptr%26lt;V%26gt; mv = %26amp;*v; line is what creates a "pinned" pointer to the boxed value type. The "%26amp;*v" says to assign the address to the pinned pointer of the data which is pointed to by the pointer 'v'.





You can then change the value through the pinned pointer and your structure's member will be changed as well.
Reply:V *v=new V;


Creating a pointer object v, of a Class V.





v-%26gt;i=8;


Assigning value 8 to member variable i of object v.





%26amp;v is the address of pointer v.

surveys

Questions related to c & java?

about pointers in c.


operators in java

Questions related to c %26amp; java?
lol
Reply:Yes, There is a concept in C called "Pointers" with which you can have variables that contain Address as their value.





And yes, There is a concept in every programming language, which is called "Operators", that refers to those special symbols used to perform a simple task. For example, the "++" Operator (without the quotes) is used to increase the amount of an integer value by 1.





What else do you want to know about them?
Reply:Go to this site to get full details of pointers in C.





http://www.cs.cf.ac.uk/Dave/C/node10.htm...





Good bye.
Reply:What a silly qn?


Is it true that pointers in C increase execution speed of the program and why?

I heard 2 arguments.First is that as pointers directly work with memory execution speed increases.Second is that ,memory handling is difficult ,so execution speed decreases.

Is it true that pointers in C increase execution speed of the program and why?
it can be true, depending on how you use them. For example if you pass a pointer to a class or function, you have ONLY passed that memory address to that class/function (and not copied the value in the variable which contains the data) which means that you have passed that variable much faster than if you were to use an actual non pointer variable or pass a variable by value.





Pointers are fast because they contain only memory addresses so the entire contents of the variable is not copied and passed which would be much slower.





Also to answer the second part of your question, yes in large programs memory handling can be difficult, pointers are active for the scope they are placed in (provided the programmer is linking to an object ONLY, and put a deconstructor into that object), put one at the start of your program and forget to delete it, well then now you have a major problem (a memory leak). I had a programmer friend that complained about his boss always saying, son its not your memory you need to stop pretending like it is, he was fresh out of college when he got that job, and his programming skill did increase when he got it.


Honestly though, it really does depend on the way you use them as well as the algorithm you go by.
Reply:pointers unlike variables do not store the value. instead they store the memory address of the variable that stores value. when we want to get the value pointed by the pointer using *ptr then the system do not need to find the memory of the value since it is already stored by the pointer. this makes working fast. u said that execution speed increases which is true.


Also, u said that memory handling is difficult. either u have misunderstood the question is a problem. one of the solution to ur next question is that pointer deal with memory directly. so it is very difficult to debug( find error ) from a program using pointers. so this makes the program development slow and not program efficiency slow. this is other concept beyond programming and is studied in software engineering.


i think u have under stood the use of pointer. it has merit of fast execution but demerit of slow program development.
Reply:Yes, pointers increase the execution speed because it directly points to the location of a variable, the value can be retrieved and processed in a short span of time.
Reply:Pointers don't magically increase or decrease anything. In some instances, pointers can be detrimental. So, what is a pointer? It's a variable that contains an address to a memory location. This is important: pointers are still variables. They take memory as well. If you're pointing to a char byte, using a pointer instead of a char isn't going to increase your efficiency, and may decrease it instead.





Pointers are useful when passing variables around in say, functions. What happens in C is that the variable is copied. So let's say you had a 100KB variable (like an array) in a struct. You don't want to pass that struct around by value, because your program would be forced to copy those 100KB. It's more efficient to refer to that memory location with a pointer, and then use that pointer to refer back to the value.





Note that you can shoot yourself in the foot with pointers. What happens if you have a memory location only known by its pointer, and then forget about the pointer (your pointer var goes out of scope, you accidentally assign another memory address, etc.)? You don't have a way to access the original memory location, and that memory sits around unused. Known as memory leaks.
Reply:Pointers increases the execution speed ,its rite...





it is one of the advantages of pointers,thts y we r going for pointers!!


[Pointers in C] What does this mean to an array of integers?

int a[10]={1,2,3,4,5,6,7,8,9};


int *p=a;


/* what does


p++


*p++


*(p++)


(*p)++


++*p


mean? */

[Pointers in C] What does this mean to an array of integers?
Arrays are the collection of similar Data Types(i.e elements) and pointers are those variables ehich holds the physical address of another variables.


Now you code


int *p=a holds the address of first element(correct would be int *p=%26amp;a)





p++ increments the address with 2 bytes because int type acquire 2 bytes in memory


*p++ means increase value at address P to 1








++*p incremtns (i.e postincrement value at address of a)
Reply:*p=a p will have the address of the variable a


p++ is post increment if we have a address as 1000 then the address will be incremented by 1 by post increment method.


*p++ will increment the value of the data present in the p


*(p++) first the value of p will be increment then address


(*p)++ this will increment the address of p value


++*p this will preincrement the p value


/* */ this is treated as multi line comment