Tuesday, July 14, 2009

Diffrence between generic pointer and pointer in c language?

1. Generic pointer is nothing but void*.


2. A generic pointer/void* can be easily type casted to the desired datatype.


3. Main differenc between the generic pointer and pointer of specific datatype: The void* is capable of pointing to the variable of any datatype whereas pointer of specific datatype say int* can point only to the variable of type int.


4. Generic pointer is also used for taking the address of the variable alone.


4. Whenever you are using void*, typecasting is required to perform the operation on the content that void* points to.


5. Be careful when you are doing any arithmetic operation with void*.


What is meant by Smart Pointer in C++ Language?

Where it necessarily in use and advantages to use this pointer?


If possible give me small snippet

What is meant by Smart Pointer in C++ Language?
In C++ you can create objects that act like pointers, but are "smarter" (well depends on how they are implemented..). Theoretically speaking they are called smart pointers simply because it usually does more actions then a default pointer.


Of course when creating these kind of objects you must design them as to have the same interface as normal pointers, meaning support pointer operations like dereferencing, indirection..


In some books you won't find the term of smart pointers, but you'll find the term of design patterns and even Pattern Oriented Arhitecture. A pattern is an object that looks and feels like something else.


In C++ standard library, there are already included some "smart" pointers, and one of them is auto ptr for example. auto ptr is generally used when you don't want to worry about cleaning up the memory after using normal pointer (auto ptr cleans up after itself automatically).


You can even create a pointer that reacts differently when being deleted. (so called pointer to NULL...)


Can address(&) be used as a pointer in c ?

We have always assigned(stored) the address of a datatype in a special variable called pointer, and then used the pointer which points to the datatype to carry out various operations. Can anybody tell me if there is a way which allows instead of storing the address in a pointer variable, whether the address of the datatype can be directly used(like a pointer) to carry out the operations on the dataype. For example, let's take the small example :





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


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





struct A


{


virtual void f()


{cout %26lt;%26lt; "Class A" %26lt;%26lt; endl;}


};





struct B:A


{


void f()


{cout %26lt;%26lt; "Class B" %26lt;%26lt; endl;}


};





int main()


{


A a;


B b;


A *ptr;


clrscr();


ptr = %26amp;a;


// My question is whether f() could be accessed somehow by using %26amp;a instead


// of using the ptr as done below


ptr -%26gt; f();


cout %26lt;%26lt; endl;


ptr = %26amp;b;


// same question for the below operation


ptr -%26gt; f();


getch();


}





I have included my question inside the code, please help

Can address(%26amp;) be used as a pointer in c ?
Yes and sort of...





By wrapping in parens, you force the expression (%26amp;a) to be resolved first, the type of the expression should be imputed as (A*), so after the first assignment of ptr, these:





(%26amp;a)-%26gt;f();


ptr-%26gt;f();





should be equivilent. However, b is (obviously) of type B, so the type of (%26amp;b) should be imputed as (B*), whereas ptr is type (A*). As such, to get the equivilent of the second assignment of ptr (without assigning a pointer) you need a type cast to override the imputed type, e.g.,





(A*)(%26amp;b)-%26gt;f();








Make sense?
Reply:Sure.





A a;


B b;


A *aa = new A();


B *bb = new B();





a.f(); /*prints Class A*/


b.f(); /* prints Calls B */


aa-%26gt;f(); /*prints Class A*/


bb-%26gt;f(); /* prints Calls B */





// playing with v-tables


b.A::f(); /* prints Class A, uses the B object data with the logic from A's f() */


bb-%26gt;A::f() /* prints Class A, uses the B object data with the logic from A's f() */
Reply:Absolutely yes. You can.


C language help regarding Mouse pointer?

well.. how to make the mouse pointer appear on a project in c??


i have the coding writen in a book which makes the mouse pointer appear in the program also reads if the mouse bottom is clicked or not but i just can seem to understand the terms used in making the program i searched the net but cannot find a specific article related to implement or initializemouse in c with clear deiscription ?? any particular sites would be helpful or a detail explanation thanku?

C language help regarding Mouse pointer?
Anything gui related will be handled by X. Assuming you're using the Xorg server (and not Xfree), then take a look over here:





http://www.x.org/wiki/Development/Docume...
Reply:In the ancient MS-Dos times mouses work on Serial port so programming is easy But now you have to know how to controll PS/2 and USB.





Check this site : http://www.daniweb.com/forums/post415481...

crab apple

C language help regarding Mouse pointer?

i am not using any server or .. it plain winxp and plain turbo c editor have made a game using graphics and ofcourse keyboard i want to have mouse interface too ?help?








C language help regarding Mouse pointer?


well.. how to make the mouse pointer appear on a project in c??


i have the coding writen in a book which makes the mouse pointer appear in the program also reads if the mouse bottom is clicked or not but i just can seem to understand the terms used in making the program i searched the net but cannot find a specific article related to implement or initializemouse in c with clear deiscription ?? any particular sites would be helpful or a detail explanation thanku?

C language help regarding Mouse pointer?
Bestever resource is


http://www.programmersheavan.com








Cheers:)
Reply:C language? So let me get this, you created a game using the graphics api? Why not use opengl/direct3d or whatever. Is your game fullscreen?


Polymorphism in C++?

Does C++ require that pointers be used to use Polymorphism in C++?





Why I ask:


I created a simple class Vehicle which has nothing except a member function called "showType()" which displays "I am a vehicle". I then created a subclass of Vehicle, Car, with a function called "showType()" which displays "I am a car". The function showType() is marked as virtual in the base class.





If I write the following code:


Vehicle test[10] ;


Car c ;


test[0] = c ;


test[0].showType() ;


The output "I am a Vehicle is produced" -- clearly no polymorphism.





However, if I change to using pointers:


Vehicle* test[10] ;


Car c ;


test[0] = %26amp;c ;


test[0]-%26gt;showType() ;





This shows the result I expect -- "I am a car". Does C++ only support Polymorphism with pointers? In some sense this seems to be logical since Polymorphism is a runtime feature, however I was a little disappointed that it couldn't distinguish in the non-pointer case -- I was hoping for a container type effect similar to Java.

Polymorphism in C++?
C++ always uses pointers to work with polymorphism and other OOP subjects.


Polymorphism in C++?

Does C++ require that pointers be used to use Polymorphism in C++?





Why I ask:


I created a simple class Vehicle which has nothing except a member function called "showType()" which displays "I am a vehicle". I then created a subclass of Vehicle, Car, with a function called "showType()" which displays "I am a car". The function showType() is marked as virtual in the base class.





If I write the following code:


Vehicle test[10] ;


Car c ;


test[0] = c ;


test[0].showType() ;


The output "I am a Vehicle is produced" -- clearly no polymorphism.





However, if I change to using pointers:


Vehicle* test[10] ;


Car c ;


test[0] = %26amp;c ;


test[0]-%26gt;showType() ;





This shows the result I expect -- "I am a car". Does C++ only support Polymorphism with pointers? In some sense this seems to be logical since Polymorphism is a runtime feature, however I was a little disappointed that it couldn't distinguish in the non-pointer case -- I was hoping for a container type effect similar to Java.

Polymorphism in C++?
The difference, Sharpie, between


test[0] = c ;


and


test[0] = %26amp;c ;


is that in the first case you are copying an instance of something to a Vehicle. In that event, all of c that is a Vehicle will be copied to test[0], and test[0] will have none of the Carness. C will remain a Car and test[0] will remain only a Vehicle.


However, %26amp;c is a pointer, so regardless of type it is cast to, it will always be a pointer to an instance of a Car, even if it is cast to a Vehicle pointer.


As a rule of thumb, yes, you will need to deal only with pointers if you are going to make polymorphism work. However, according to the technical definition, a reference is not a pointer, but as far as the machine code is concerned, it is, so this


Vehicle %26amp;v = c;


v.showType();


would also reveal it to be a Car.
Reply:That is the correct behavior in both cases.





You will only see polymorphic behavior with pointers and references.





My java is pretty rusty but I don't recall that it is different in this respect. I suspect you were storing references (whether or not you realized it) in the containers.
Reply:Its supported!!





I also am studying programming and do not know but here:


http://www.google.com/search?hl=en%26amp;q=pol...


I need a code for pascal's triangle in c++?

without using pointers (simple c++ lang)


the output should be: 1


1 1


1 2 1


1 3 3 1


and follows...........


pls help me out .....

I need a code for pascal's triangle in c++?
search google

strawberry

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


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?


Why cant we add two pointers???

pointers in c language...we can subtract two pointers then why cant add them?give logical justification!

Why cant we add two pointers???
above answer +


adding pointers don't give any useful information


consider this:


_ip is pointer to _i


_jp is pointer to _j


the where does (_ip+_jp) point to? nowhere
Reply:adding can result outofbound addresses
Reply:You can, but it has no meaning.


I live 226, bakers' street. That is my address.


He lives 10, downing street. That is his pointer.


Where is 22610, bakerdowning street????

kudzu

C++ programing this is part of my study guide and im not sure if my answers are right could you help me out?

1.The arguments in a function call must match the arguments in


the function's header


a)only when the function call is in a different file from the function body.


b)in number, order, and variable name.


c)in number and order only.


d)in number, order, and type.


e)They don't have to match the header, only the function prototype.


2.To use I/O redirection to read from a file you need to:


a.declare a file variable in your program and openit


b.use the full path name with cin (a:\file1.dat.cin %26gt;%26gt;)


c.run your program from dos and add the file to be read from with the correct operator ( myprog %26lt; file1.dat)


d.any of the above will work


3.If you try to explicitly open an ifstream or ofstream file, how can you tell if the file opened successfully?


a.use the fail() function (method)


b.a return code of 1 indicates success


c.a pointer to a buffer that will receive data will be null if it fails


d.there is no way to tell other than to try to do input of output


e.a return code of 0 for success

C++ programing this is part of my study guide and im not sure if my answers are right could you help me out?
1-d


2-b


3-c





Please select best answer if all are correct


What is difference between "member selection" (.) and "pointer to member" (->) in C++?

This is a very basic C++ question, but help is appreciated.





I'm an experianced VB.net programmer, and want to quickly learn C++. The biggest hurdle at the moment is finding the new syntax and understanding unmanaged pointers - I already understand OOP very well.





Could anyone explain simply what the "pointer to member" operator really is doing? I'm used to only using member selection. Why is a different symbol needed?

What is difference between "member selection" (.) and "pointer to member" (-%26gt;) in C++?
Pointers are one of the most confusing concepts for some people. Not everyone. Just some people. So here is a description of pointers to make sure you get it. It is central to this entire discussion.





You should also know about the %26amp; operand which is used to get the address of something. To get the address of i, you would write %26amp;i. As in:


int i = 10;


int * p = %26amp;i;


now p contains the address of i.





A pointer is a variable that contains an address to memory somewhere on the computer. Let's say i is an integer with a value of 10. That integer lives somewhere in the computer RAM. Lets say it lives at address 5555. If we have a pointer p that points to that integer, then p has a value of 5555.





Great, let's go on.





Let's say there is a structure or class containing an integer i.


so i, is a member of our class. If an instance of that class exists somewhere it has an address. The same address and pointer discussion from before applies. p = 5555, which is the address of the object(instance of class). So we say p points to the object.





This might look like this:


MyClass o = MyClass(); //create object o


MyClass *p = %26amp;o; //get the address of o





Now we want to access the member i of that class. I would put p-%26gt;i to get that value because p is a pointer to the object that contains the member item I want. At any time, you can change p to make it point to some other object.





Member selection using "." is like the original integer discussion using i.


In the original discussion, i was the actual integer. In the same way, if the object is o, then o.i is the member i of object o.





In the example above, p-%26gt;i is refers to the same value as o.i;
Reply:Their is a difference, if the . operator is used, then the memory address that is manipulated is the address of the object being accessed plus the offset where the data is stored. If the -%26gt; operator is used, then the value of the pointer plus the offset is used to access the correct memory location.





Also, in C++ we can overload operators, including -%26gt;, which can allow for some interesting syntax.
Reply:Pointer to member operator (--%26gt;)will call the methods or members at runtime(dynamically). In C++ we have virtual functions . To call those functions we use pointer to member.





Where as we use member selection where call class members at compile time.


Write Programming in C using pointer (Challenge for C programmer)?

1) write a program to compare two strings using pointer


2) write a program to print prime numbers between 1 to 500 using pointer


3) write a program to sort two dimensional string array using pointer

Write Programming in C using pointer (Challenge for C programmer)?
Hardly a challenge - this is basic stuff.





It is also obviously HW. But I will give you some pointers.





1) this what strcmp does - look at the source code for strcmp


2) someone wants to make sure you know the difference between the pointefr and the data


3) use strcmp and a linear sort. Just switch the pointers - not the strings.





Good Luck


Write Programming in C using pointer (Challenge for C programmer)?

1) write a program to compare two strings using pointer


2) write a program to print prime numbers between 1 to 500 using pointer


3) write a program to sort two dimensional string array using pointer

Write Programming in C using pointer (Challenge for C programmer)?
Asking people to do your homework is one thing, although you learn nothing from it, asking 4 times is just going too far.
Reply:it is difficult to fool people. No body wants to accept challenge of this type :-) hehehehehe


sorry, i am not laughing.
Reply:u should do ur homework by urself

garland flower

Write Programming in C using pointer (Challenge for C programmer)?

1) write a program to compare two strings using pointer


2) write a program to print prime numbers between 1 to 500 using pointer


3) write a program to sort two dimensional string array using pointer

Write Programming in C using pointer (Challenge for C programmer)?
lol


thats y ,i hate pointers ...


thanks GOD


i am using java ,no more pointers..


check this website it may help you


http://www.codersource.net/codersource_c...


C++ >> Object and pointer?

I am a newbie in C++ programming.





What is the different effect in using object and using pointer??

C++ %26gt;%26gt; Object and pointer?
In addition to what the previous answerer said, if you use a pointer, you change the values of the object itself. If you use an object then you might change the object itself or just a copy of the object depending on the situation. Here are three examples:





Let's say we have an object called "someObject" and it contains an attribute called number.





Example # 1:





int main( )


{


someObject a;


a.number = 10;


cout %26lt;%26lt; a.number; // This is going to print out 10


function(a); // see what "function" does below


cout %26lt;%26lt; a.number; // This is going to print out 10 not 20


return 0;


}





void function(someObject a)


{


a.number = 20;


}





In the previous example, we are using objects (not pointers to objects). So, if you change the object's values within the scope of where you created the object, then the values of the object itself are going to change. If you pass the object to a function (by value), any changes you make to that object are actually done on a copy of the object not the object that you passed to the function itself. Therefore, assigning 20 to the object in the previous example did not affect the value of (a) within main.





Example #2:


If you still want to use objects, not pointers, and you want the changes you make to the objects to affect the origional object not a copy of the object, you have to pass the object to functions by referrence as follows:





void function(someObject%26amp; a) // note the additional '%26amp;' here


{


a.number = 20;


}





Example #3:


There are two reasons why you would want to use pointers to objects rather than the object itself:





1) Because you want changes to the object anywhere in your program to affect the object itself not a copy of it.





2) Because you want to save space as the previous answerer stated. That's because functions don't create copies of the object you pass to them anymore.





NOTE: passing by referrecne as in the 2nd example does the exact same thing (and has the same benefits) as pointers.





Here is how you would do that:





int main( )


{


someObject * a;


a-%26gt;number = 10;


cout %26lt;%26lt; a-%26gt;number; // This prints out 10


function(a);


cout %26lt;%26lt; a-%26gt;number; // This print out 20


return 0;


}





void function(someObject * a)


{


a-%26gt;number = 20;


}





I hope this helps!!
Reply:When an object is created, space is allocated to all of the data members for that object so it takes up (or can take) a lot of memory space. On the other hand, a pointer is just a reference to the memory address of an object and we know that a memory address will take up a very little space (only 2 bytes in case of integer pointer)
Reply:Can't add much to what Silver Sword wrote, but maybe just a few notes on syntax and symantics on pointers and stuff because it can be confusing for a newb (I was there once).





int a; // a regular int


int* ptrI; // read int* as "pointer to an integer". It literally contains a memory address, it might be something like 0x0bf080c4





ptrI = %26amp;a; // this means "take the address in memory of a and store it in ptrI





*ptrI = 15; // this means "go to the address out in memory ptrI specifies and store the value 15 there"





cout %26lt;%26lt; *ptrI %26lt;%26lt; endl; // this outputs 15


cout %26lt;%26lt; a %26lt;%26lt; endl; // so does this because ptrI points to a





a = 30; // store 30 into a, and since ptrI points to a, *ptrI == 30 as well





The other piece of pointer syntax is -%26gt;. If I have a pointer to a Person object that has a data member called "name", I can access "name" in one of two ways:





Person* p;


(*p).name = "me"; // way 1


p-%26gt;name = "you"; // way 2





Both ways do the same thing.





One other thing about "%26amp;". You can use this in the way I wrote above, or in a function definition:





void foo(int%26amp; x);





int a = 6;


foo(a); // this is implicitly passing the *address* of a to foo. Any change I make to "x" in foo() will affect "a" when foo() is done running.





This is equivalent to this:





void foo(int* x);





int a = 6;


foo(%26amp;a); // this explicitly passes the address of "a" to foo


C problem, function & pointer declaration error?

Hi,


When i run this code, I get the following error. When i remove the function declarations it compiles. But function+pointer declarations give the error!


Urgent project deadline - please help!!


Error 1 error C2143: syntax error : missing ';' before 'type' c:\nofrduk\Microscribe2\MicroRun7...








void main(){


FILE *posrot;


char letter;


float DeltaLonger=0.25f; // Diff. by which special stylus tip is longer than original one


double A; // declare stylus rotation angle


arm_rec arm; // declare "struct arm_rec"


arm_init(%26amp;arm); // initialize "struct arm_rec" for further use


arm_length_units(%26amp;arm,MM); // want millimeters


arm_angle_units(%26amp;arm, DEGREES); // want degrees





double ** p1 = (double **)malloc(sizeof(double)*ROW*COL);


double ** p1_t = (double **)malloc(sizeof(double)*ROW2*COL2);

C problem, function %26amp; pointer declaration error?
Are you trying to call the functions or declare them in main()? If you're declaring them they need a return type. If you're calling them then they need declaring outside the scope of main() and also defining. The code snippet you've given also doesn't include any definition or declaration of the structs you're using - you'll need these as well.





Also main should always return an int.
Reply:things would be so much easier if you could post the error message, and not just truncate it.





you have a lot of problems in the code.





// is not a valid comment for C, only for C++. But you say you have a C problem.





you didn't include header files.





your declaration of p1 and p2 is AFTER executable code - that's not allowed in C, only in C++. You have to move the declaration of p1 and p2 to the top of the function, below "arm_rec arm;" or "double A;" .





etc. etc.


Pointer problem in c++ regarding user input?

I wrote a simple test case to see how pointers work in c++. I want to know how to take input from a user and store it in memory that was allocated using the new keyword. However my cout statements generate incorrect results.





#include%26lt;iostream%26gt;


using namespace std;





void main()


{


char* fname;





//allocate memory


fname = new char[20];





//allow up to 5 input characters


cin.get(fname,5);





//prints value without dereferencing?


cout %26lt;%26lt; fname %26lt;%26lt; endl;





//does not print addressess?


cout%26lt;%26lt;"index 0 address " %26lt;%26lt; %26amp;fname[0] %26lt;%26lt;endl;


cout %26lt;%26lt;"index 1 address " %26lt;%26lt; %26amp;fname[1] %26lt;%26lt;endl;


delete[] fname;


}





Say my input value is ‘ab’, the pointer fname which I thought holds the address to the allocated memory prints the value ‘ab’ without dereferencing. It seems that fname holds the actual value rather than an address. Furthermore %26amp;fname[0] and %26amp;fname[1] print the values ‘ab’ and ‘b’ respectively instead of the individual index addresses. If someone could comment on these 2 issues it would be helpful.

Pointer problem in c++ regarding user input?
when you send a char* for cout,it considers that


starting address of a string,and writes the string


to output for you,


in all cases you are sending a char* to cout,


he doesn't know what you mean, he thinks


you want a string of chars in output,





computers do what you say,not what you mean.
Reply:try modifying the following statement:





//allow up to 5 input characters


cin.get(fname,5);





to


cin.get(*fname,5);

blazing star

Can any one send me the few practice examples pointer in c/c++?

i want to learn the diffficult questions regarding the pointer in c


so any who is aware can send me this

Can any one send me the few practice examples pointer in c/c++?
More information needed


Delete pointer in c++?

class A{





};





class B: public A


{





protected :


A *a;


public:


~B()


{


if(a !=NULL)


delete a;%26lt;------------ core dump here


}


void fun();





};


void B::fun()


{





a= new c[5];





}





class c:public B


{








};








How to delete pointer a?


destructor of all classes are virtual.

Delete pointer in c++?
You should first initialise pointers to null in constructor. If you don't do this pointer will not be NULL ( if(a!=NULL) ) it will be undefined. you will be trying to delete an undefined memory address.
Reply:first have a forward declaration of class c right at the top coz ven u r trying to allocate memory in b till data stage c is not known to compiler





second u can have a try block in fun() which allocates dyn mem


and a catch block which takes as a paramater of bad_alloc coz new ven fails throws a bad_alloc exception error





Other option is u need to overload the new operator so dat u tel lthe compiler that it can take an argument of class c type


Pointer to a pointer in C programming?

can you please explain to me the advantages of using pointer to a pointer in C programming?.





I also dont know how i can use them.


try to give me an example.

Pointer to a pointer in C programming?
Here's the deal - pointers to pointers are the SAME as multidimensional arrays in any other language.





Consider this:


int[][] matrix;





This is a 2-d array of numbers, such as a reachability matrix for a graph. You need this 2-d array to perform operations such as finding the shortest path between 2 points, or finding the number of distinct paths, or any other graph-operation.





You can use pointers to pointers to simulate this kind of 2-d array. Look at this for more info:


http://computer.howstuffworks.com/c32.ht...
Reply:There are a number of applications the most common is to assign a ptr in a function.


e.g.





int assign_ptr(int **a)


{


*a = malloc(8);


return 1;


}


yeah it's a nonsense example but it shows the point.


Function pointer - C++ code section?

I came across following section of code %26amp; it is working with a highly complex system.


Can someone provide some explanation on this like which constructor is being called %26amp; where parameter pCallback is being sent %26amp; what is the meaning of void(*)(void*)%26amp; a::afoo mean?








===================================


a.h


static void afoo ( void * );





a.cc


void a::afoo ( void * pCallback )


--------------------------------------...


file b.h


b ( void );


b (


void (* pStatsUpdate ) ( void * ),


void *


);





file c.cc


new b (


( void


(*) ( void * ) ) %26amp; a::afoo,


this );


===================================

Function pointer - C++ code section?
It does not look sensible to me. The retyped text probably contains some syntax error, For example,





a.h


static voidafoo ( void * );





should be





a.h


static void a::afoo (void*);





or it must be part of a class or namespace declartaion as





class a {


// ...


static void afoo (void*);


//...


};





or





namspace a


{


//...


static void afoo (void*);


//...


};








It is also important to know in which part of the code these declarations and / or defintions take place.





This faily complex structure is either generatated by some auto code generator software, or some programmers that do not like to make their minds clear when they do programming.








The expression void(*)(void*)%26amp; a::afoo means a pointer to any function which returns a void and takes a void * as its only argument such as





void f (void * vp)


{


//...


}





a::afoo class method or namespace function obeys this signature, and therefore, it is qualified to be cast to this type.





I think yet there is another mistype with the %26amp; in this part unless it means a pointer to a pointer to the function (and not the pointer to function itself).
Reply:void(*)(void*)----means a functin pointer, that takes a pointer as parameter and does not have a return value............








the use of %26amp; is the change in function will in turn effect the actual arguements.....





for that paarmeter pCallBack, i think it will return the value to the constructor in a.h, provided you mention its location...

imperial

Is this what a C++ pointer is in a nutshell?

I ran this test on my compiler





#include %26lt;iostream%26gt;





using namespace std;








int main()


{


int x, y, *z;


y=8;


z=%26amp;y;


x=y;








cout%26lt;%26lt; "x= "%26lt;%26lt; x %26lt;%26lt; " " %26lt;%26lt; "y= " %26lt;%26lt; y %26lt;%26lt; " " %26lt;%26lt; "pointer z= " %26lt;%26lt; *z %26lt;%26lt;"\n"%26lt;%26lt;endl;


system ("PAUSE");


return 0;


}


And all of them returned 8. I then tried to see what would happen if I did





int main()


{


int x, y, *z, *q;


y=8;


z=%26amp;y;


x=y;


*q=z








cout%26lt;%26lt; "x= "%26lt;%26lt; x %26lt;%26lt; " " %26lt;%26lt; "y= " %26lt;%26lt; y %26lt;%26lt; " " %26lt;%26lt; "pointer z= " %26lt;%26lt; *z %26lt;%26lt;" " %26lt;%26lt; "pointer q= "%26lt;%26lt;*q%26lt;%26lt;"\n"%26lt;%26lt;endl;


system ("PAUSE");


return 0;


}


But the DOS window stopped and became unresponsive.


Taking what I got from the first test, I made this analogy, and I assumed


z:%26amp;y::*z:y


Basically, I deduced that z stores the address of y, and *z points to the data stored in the address of the variable y(0x22ff50).


So basically, is a pointer just something that points to the data stored in a memory address?

Is this what a C++ pointer is in a nutshell?
A pointer is just something that stores the address at which another variable's value can be accessed. It points to the actual data stored at that address when you use the dereference operator (*). They are often useful when changing individual memory address, like when making cheats through code injection. For example, the money value in GTA:San Andreas might be something like 0x006FFF. They I could change the money using:


*(int*)0x006FFF = 1337;


This means that it wants to change the value at the address held by 0x006FFF.


C program for deleting those words starting with s n ending with letter d in a string without using pointers.?

Without using pointers is not really possible.


You can use the string as an index like this;


if (s[i] == ........


but actually s[i] is still a pointer.


Anyway you can avoid using * and %26amp; this way, if hats what you mean?


Then write your own string search functions.


the standard string search and compare functions are returning pointers.


Wap using pointers to calculate the sum of all elements of an array that are above 20 using c program?

int getSum(int *P)


{


int X;


int sum;





for (x=0;x%26lt;strlen(p);x++)


{


if (p[x] %26gt; 20)


{


sum = sum + p[x];


}


return sum;


}


}





For more free C/C++ source codes, visit: http://smartcoder.co.nr








KaBalweg


http://smartcoder.co.nr


Wap using pointers to calculate the sum of all elements of an array that are above 20 in c program?

main () {


printf("Write your own programs :)");


}

elephant ear

How can I use pointers to transfer the contents of an array to another of the same size and type in C++?

I need to transfer the contents of a 20-item char array of one object to another, and I'd really like to avoid using for loops (I have to do this several thousand times). is there a way to set a pointer to the first array, and transfer its contents to the second?





Thanks!

How can I use pointers to transfer the contents of an array to another of the same size and type in C++?
With a little work you can reduce the number of steps.





You can cast a pointer to long int to point to your array and move 8 bytes at a time, *only if* you assure that each of your arrays is 8-byte aligned.





The best way to do this is something like the following:





long fakeArray[3];


char *charArray = (char *)fakeArray;





then to copy do something like


long *longPtr = fakeArray, *longPtr2 = fakeArray2;


*longPtr++ = *longPtr2++;


*longPtr++ = *longPtr2++;


*longPtr++ = *longPtr2++;





Maybe even make this a macro:





#define COPY(AAA, BBB) {long *longPtr = (long *) %26amp;(AAA), *longPtr2 = (long *) %26amp;(BBB);\


*longPtr++ = *longPtr2++;\


*longPtr++ = *longPtr2++;\


*longPtr++ = *longPtr2++;\


}





Notice if you do this each of your arrays will need 24 bytes instead of 20, so if you really have a lot of them it will make your memory image larger.





It is often said that premature optimization is a real enemy to good code. Computers are really fast, my guess is that copying short arrays is not going to slow you down very much. Why don't you write the program normally first and then run a profiler to see if this is a problem or not?
Reply:I don't know. I know when programming for Palm, there is an api call named MemMove which will do this, but I don't know for windows.





Maybe you should write that segment in assembly, that would make it quick, but not so easy :)





Hope that helps!
Reply:sorry, u must use a loop to increment the pointer's position


but i guess u can use something called memcpy "it's C not C++ , but i guess u will find it in C++"


or u can use any function that maniuplate strings in C++ like strcat or strcpy and this stuff


sorry if i didn't give u a big help but im really not good in C++, u should move to C# coz it's much better


Write a c++ program to read an inteegers and display that inteeger without using arrays & pointers ?

To display a single integer





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


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


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


void main


{


int num;


cout%26lt;%26lt;"Enter a integer ";


cin%26gt;%26gt;num;


cout%26lt;%26lt;"\n The integer entered is "%26lt;%26lt;num;


}








To display multiple integers





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


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


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


void main


{


int num,i,count;


cout%26lt;%26lt;"Enter the number of integers you want displayed ";


cin%26gt;%26gt;count


for (i=1;i%26lt;=count;i++)


{


cout%26lt;%26lt;"Enter a integer ";


cin%26gt;%26gt;num;


cout%26lt;%26lt;"\n The integer entered is "%26lt;%26lt;num;


}


}


When are pointers pass by value and when are they pass by reference in a c++ function?

Passing by value and passing by reference are the same for pointers as for ordinary variables.





When passing a pointer by value, you're actually passing the address that the pointer points to.





When passing a pointer by reference, you're passing the address of the pointer, which itself is the address of some other item.





Passing by reference allows you to change the location that the pointer points to whereas by value just lets you use that address - it'll have no effect on the pointer when the function returns.

When are pointers pass by value and when are they pass by reference in a c++ function?
Pass by value when you want to retain the original value regardless of changes to the value inside the function.


Pass by reference when you require the original value to be changed.


C++: When do you decide to pass variables by value, reference, or pointers?

Two situations:


1) When we want to modify the actual variable passed as the function parameter


void swap(int %26amp; a, int %26amp; b) ==%26gt; Swaps values of a and b.


2) If we do not want to make copy of the parameter for example


void display (const int%26amp; n) // pass by reference.


Here you do not want to change the variable n , also you do not want to create a local copy (if u pass by value a local copy will be created).

C++: When do you decide to pass variables by value, reference, or pointers?
It is purely based on requirements %26amp; operations
Reply:Pass by value if it's small, for example integers or characters or pointers. Pass by reference if you want to save a memory copy and the value you pass should not be null. Passing by reference is similar to pointers, in that only a pointer sized piece of memory will be transmitted, however it's understood that passing by reference implies the object is not null. Pass by pointer if you want to save on memory copy and the value could be null (in which case null might be a special sentinel value condition).
Reply:it's a tricky question, and you need some experience to decide what to do.





by value: i always pass by value, unless i'm passing an object. if you pass by value, the value is copied; if you're passing an object (i.e. std::string or your own objects) by value, the copying can cost performance, and therefore i want to avoid it.





by pointer: that's what i use if the original value should be modified. You can also use references in that case, but there's one difference: a pointer can be NULL, a reference cannot be NULL. sometimes i use this feature to signal that this variable can be optional (by setting it to 0).





reference: i don't like references, therefore i don't use them a lot. but i do like const references. they are useful, especially if you want to avoid copying objects.
Reply:First you have to choose pass by reference if the


function or method is permitted to (and is capable of) modifying the actual argument. This implies that the argument must be an expression (lvalue) that


can reasonably be modified. Example : swap function.


But if you are using the value of the argument to compute a new value or do something else, it's cleaner to pass by value, except if there is performance issue such as the following.


Here is a recommendation by Meyers (Effective C++) :


prefer pass-by-reference over pass by value, except for built-in types and STL iterator and function object types.


So if your copies are lightweight enough , pass-by-value but if you are passing something large like an struct, choose pass-by-reference or pointer .


choosing between pointers and references is more of a style preference as there is no difference in performance .pointers are more explicit than references, if we do not go with pass-by-value. So they make a cleaner interface.

lady palm

Write a function in C to split a list into two sub-list using pointers?

There's not enough information, what type of list, I don't think you mean an Enumerated List, and into what type of split, are you talking about linked lists, or something like indexing using trees to navigate or manage keys?

Write a function in C to split a list into two sub-list using pointers?
data structure, you are reading, good,
Reply:For i=0 to 10


who_cares=me


Next


Why do i need to derefence pointers when passing them to a function in the C languge?

Because a pointer is also a value that is perfectly legitimate to send into a function. Because you might be trying to actually send the pointer instead of the value that the pointer points to.





That would be called "pass by reference".


Example:





void PassByReferenceFunction( int * referenceToInt )


{


printf("I got %d!\n",*referenceToInt);


}





void main()


{


int value=10;


int * referenceToValue = %26amp;value;


PassByReferenceFunction( referenceToValue );


}





As you can see, we can pass the pointer into the function, and we can get the value by using the * operator before the pointer. This is very useful if we want the function to change the value of multiple parameters and have them stay changed when you return.





I imagine what you are doing is "pass by value".





Example:


void PassByValueFunction( int value )


{


printf("I got %d!\n", value);


}





void main()


{


int value=10;


int * referenceToValue = %26amp;value;





PassByValueFunction( *referenceToValue );


}





In this case, we are dereferencing the pointer outside of the function (in the function call) when we send "*referenceToValue" as the parameter to PassByValueFunction.





C (as opposed to C++) by default gives you a lot of leeway to mix and match types for your own purposes. It's very low level... it assumes you know what you are doing. Maybe you WANT the value of the pointer instead of what it points to. This is very powerful, especially when you are accessing hardware directly. Pointers are the most basic and powerful concept in C coding.


This is my first time with C++ STL. i am writing a function where I store pointers in a list.. Please help!!?

i am getting a reference to a variable in my fucntion


funct(ABC);





void funct ( XYZ%26amp; x) {


// I need to store a pointer to ABC in a list.





Can u suggest an efficent way of doing this. Also I am not sure of the scope of ABC. Please adive





}

This is my first time with C++ STL. i am writing a function where I store pointers in a list.. Please help!!?
typedef struct _list


{


struct _list *next;


void *data;


} List;


List *list_of_data;





void funct(XYZ %26amp;x)


{


List *list_p;


list_p = (List *) malloc(sizeof(List));


list_p -%26gt; data = (void *)x;


list_p -%26gt; next = list_of_data;


list_of_data = list_p;


}
Reply:can u make your question a little clearer please
Reply:It depends on what you mean by list. The most straightforward list is an array, but I’m assuming you want an expandable list? In which case std::vectors would be useful. But that’s just an arbitrary list of pointers. Does each pointer have any significance to it? Do you attach a name or arbitrary number to each pointer? Then you’ll want a std::map.





Might be useful: http://cppreference.com/





One more thing. Is there a reason you pass a reference to your object as opposed to a constant pointer to it?


Binary tree programming in C++?

How can i make a binary tree (eg BST) using C++ pointer/reference method?





can you please give me some code.


I know that each node will have one box to store the item and two boxes to store the pointers to each of its siblings.





but i dont know how to code it... please help me.

Binary tree programming in C++?
This could be an example:





class node


{


private:


node *m_left;


node *m_rigth;


//a property that holds some value i.e. int value;


public:


//contructor


//destructor


*node get_left();


*node get_rigth();


void set_left(node * left_node);


void set_rigth(node * ritgth node);


int get_value();


void set_value(int value);


};





The members rigth and left node are of the same class node
Reply:There are plenty of educational institution that publish relevant materials in the internet, simply yahoo or google them.





Among what I found are:


http://cis.stvincent.edu/html/tutorials/...


http://math.hws.edu/eck/cs225/s03/binary...





http://cslibrary.stanford.edu/110/Binary...





HTH!

snow of june

Please I want to connect two pointers and it is not working. i am programming in c++ with dev compiler.help me

/*i want to connect frisk pointer and blackee pointer please help me.thanks*/





#include %26lt;iostream%26gt;


using namespace std;


class Cat


{


public:


int GetAge();


void SetAge (int age);


void Meow();


Cat *blackee;


private:


int itsAge;


};


int Cat::GetAge()


{


return itsAge;


}


void Cat::SetAge(int age)


{


itsAge = age;


}


void Cat::Meow()


{


cout %26lt;%26lt; "Meow.\n";


}


int main()


{


Cat *Frisky;


Cat *blackee;


blackee-%26gt;SetAge(4);


Frisky-%26gt;blackee;





cout %26lt;%26lt; "Frisky is a cat who is " ;


cout %26lt;%26lt; Frisky/*.GetAge()*/ %26lt;%26lt; " years old.\n";


return 0;


}

Please I want to connect two pointers and it is not working. i am programming in c++ with dev compiler.help me
OK First of all you need to understand the difference between a pointer and an instance of a class.





Please read the references and they should explain to you why


blackee-%26gt;SetAge(4) is causing your program to crash and how to fix it.





Namely you need to create instances of Cat not just pointers to them. As for connecting them the pointers tutorial should help you out with that.
Reply:Its been a while since I have written in C, but I think there are 3 things I see:








(1) You need to allocate the memory for blackee based on your code here.





ie: Cat *blackee = new Cat();








(2) The second is on the assignment of Frisky to blackee, it should just be:





Friskey = blackee;








(3) Although it is commented out, you appear to be using the '.' operator for accessing the GetAge() method on Frisky. This should be the -%26gt; operator (because you are accessing the method on the pointer to the object). If you were accessing it on the object (ie: Cat Friskey;), then you could use the '.'.








In this instance, the code would have 2 pointers to the same Cat object. I am not sure if you need both objects (may if the assignment asks for it perhaps), but you could get away with the followibng code instead:





int main()


{


Cat *Friskey = new Cat();


Friskey -%26gt; SetAge(4);





cout %26lt;%26lt; "Friskey is " %26lt;%26lt; Friskey-%26gt;GetAge() %26lt;%26lt; " years old.\n";





return 0;


}








Although it might be interesting for you to do the following:





int main()


{


Cat *Friskey = new Cat();


Cat *blackee;





blackee = Friskey;





Friskey -%26gt; SetAge(4);





// both should be the same age.


cout %26lt;%26lt; "Friskey is " %26lt;%26lt; Friskey-%26gt;GetAge() %26lt;%26lt; " years old.\n";


cout %26lt;%26lt; "Friskey is " %26lt;%26lt; blackee-%26gt;GetAge() %26lt;%26lt; " years old (via blackee pointer).\n";





return 0;


}


(C++) How can I get the size of an object from a pointer to a base class?

class Class{


public:


int Something;


};





class DerClass : public Class{


public:


int Array[256];


};





main()


{


Class*C = new DerClass;


sizeof(*C); // = 4


sizeof(DerClass); // = 1028


}





// How can I get 1028 from pointer C?

(C++) How can I get the size of an object from a pointer to a base class?
As far as I know, in c++ it is impossible to get the size of an object just from the base class and sizeof function. One way to get around this is to use dynamic_cast as follows.








struct A {


int a;


virtual ~A() {}


};





struct B : public A {


int b[128];


virtual ~B() {}


};





struct C : public A {


int c[256];


virtual ~C() {}


};





size_t sizeofA(A* a) {


if (dynamic_cast%26lt;C*%26gt;(a))


return sizeof(C);


else if (dynamic_cast%26lt;B*%26gt;(a))


return sizeof(B);


else


return sizeof(A);


}
Reply:sizeof() hard codes size of objects into the program at compile time. Allocated (ie: 'new') memory block sizes are unknown until run time, making sizeof() hopeless to help.





So, don't think it can be done via pointer.


Write a C program for the implementation of Linear Search using pointers.?

Linear search is basically looking through an array of values sequentially, stopping when you find what you're looking for, or the end of the array.





Some pseudocode that should do what you're asking:





- create or get an array of values (what type?)


- declare a pointer variable of the same type as array, call it 'curpos' (for 'current position')


- initialize 'curpos' to point to the first value in the array


- while 'curpos' doesn't point to just past the end of the array


---- compare the value pointed to by 'curpos' with the value you're looking for


---- if they're equal, you're done


---- otherwise, move curpos to the next position in the array





- if you get to just past the end of the array and haven't found what you're looking for, signal an error


How many levels of pointers can be handled at a time in C Language for different types of compilers?

To my knowloedge, the answer is that it depends on the types of pointers and the memory available and the kernel itself. Think about it as the weakest link problem. If you have run out of memory to allocated a pointer, it will fail. Alternatively, if you kernel limits your file pointers (such as linux) with a hard limit, you will also find the allocation to fail. Generally, you should consider this limitation by learning about the kernel you are developing on and the amount of dynamic memory it can allocate.

How many levels of pointers can be handled at a time in C Language for different types of compilers?
32

sweet pea

Write a program in c for strcmp without using library function with pointers?

iam serching job somany comapnies asking this question but iam not getting lz reply anybody

Write a program in c for strcmp without using library function with pointers?
/*


* myStrCmp compares two strings s1 and s2 and returns an * integer value which would be 0 if the strings are equal or else the * difference of ascii of first letter.


*/


int myStrCmp(char *s1, char *s2)


{


int diff=0;





//check for invalid input or arguments.


if(s1==NULL || s2==NULL)


{


printf("Invalid input");


exit(1);


}





while(1)


{





// if either of string ends then break the loop.


if(*s1 =='\0' || *s2=='\0')


break;





//if the character is equal then increase the pointers and continue the loop.


if(*s1 ==*s2)


{


s1++;


s2++;


continue;


}





//if they are different then subtract and break the loop


if(*s1!=*s2)


{


diff=*s1-*s2;


break;


}


//end of infinie loop


}





return diff;





}
Reply:#include%26lt;stdio.h%26gt;


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


main()


{


char a[30],b[30];


int n;


clrscr();


printf("enter string1 :\n");


gets(a);


printf("enter string2 :\n");


gets(b);


n=xstrcmp(a,b);


printf("the difference value=%d",n);


getch();


}





int xstrcmp(char *a,char *b)


{


while(*a==*b)


{


if(*a==NULL) //case when 2 strings


return(0); //entered are the same


a++;


b++;


}


return(*a-*b);


}


Write a program in c for strcmpi without using library function with pointers?

iam serching job somany comapnies asking this question but iam not getting lz reply anybody

Write a program in c for strcmpi without using library function with pointers?
int strcmpi(const char *s1, const char *s2)


{


for (;;){


if (*s1 != *s2) {


int c1 = toupper((unsigned char)*s1);


int c2 = toupper((unsigned char)*s2);





if (c2 != c1) {


return c2 %26gt; c1 ? -1 : 1;


}


} else {


if (*s1 == '\0') {


return 0;


}


}


++s1;


++s2;


}


}
Reply:is it c++ ?
Reply:You can't. You have to use libraries.

bottle palm

Am going to Washington, D.C. for the first time. Any helpful pointers to make the trip go smoothly?

I am interested in touring the historical sites. Can someone recommend an economical tour package? Also, night spots, restaurants, etc. for the 30-somethings? Best (and worst) hotels? Areas to stay away from? Thanks.

Am going to Washington, D.C. for the first time. Any helpful pointers to make the trip go smoothly?
Tours... I only recommend two:





Monuments by Moonlight http://www.historictours.com/Washington/... because DC is just beautiful at night, plus the weather is much more comfortable if you'll be here before October





Heritage Walking tours:


http://www.culturaltourismdc.org/informa... These are self-guided and free and you really get to see the city up-close and personal, and absorb some history while you're at it. This link is for the downtown route but I also recommend the Adams Morgan and/or U Street because both go through the trendy/hip and happening neighborhoods. You'll have a lot of good restaurants and nightspots to wander into, although in Adams Morgan on a weekend evening you will want to stick to the lower end of the "strip" because the further up the hill you get, the younger the crowd (and the bigger the crowd) is.





Nightspots... for a "neighborhood dive" try the Big Hunt on Connecticut Ave, outstanding beer selection, great jukebox and great pub fare, and pool tables. For dressing up and dancing try Dragonfly, also on Connecticut Ave. For live music, the 9:30 Club (8th and V NW) is a world-class venue that gets some top-name acts and has an amazing sound system, or try the Black Cat on 14th and S NW for local bands and indie bands.





Hotels: Economy-minded, I'd recommend the Days Inn on Connecticut Ave NW near UDC as the neighborhood is very nice and safe, metro is 2 or 3 blocks, free parking, and a small but nice selection of restaurants nearby. Higher priced, I'd pick the Governor's House on 17th and Rhode Island NW for excellent service and great location, or the Embassy Suites on Massachusettes Ave NW (near I think 21st Street). Do not not not stay anywhere on New York Avenue NE (New York Ave NW higher than the 800 block or so is fine although very quiet at night). Do not stay on Bladensburg Road or in the "Capital Gateway" neighborhood of DC itself. I'd also recommend checking into some of the Arlington, VA hotels, particularly those on/near Wilson Blvd, or Clarendon Metro; there may be fewer posh amenities but the prices are lower and the location is awesome.





Restaurants... be sure to try Ethiopian while you are here, as DC has the largest Ethiopian community outside of Ethiopia itself and we have many fine restaurants to choose from. I recommed Dukem on U Street (around 9th or 10th); their food is pretty good and very affordable plus most nights they have a dinner show with traditional Ethiopian dance and music. If you have never had Ethiopian food, it's not the prettiest but it's very yummy and fun to eat; no forks! Pick it all up with your fingers on squishy "napkin bread."





Neighborhoods to stay out of: the city has changed a lot in the last few years and former "bad" neighborhoods are now fun. Steer clear of the neighborhoods that are mostly residential; Southwest DC is not overly dangerous but there's not a lot to do there. Parts of Southeast can be a little rough but if you stick close to Capitol Hill/Mass Ave/Penn Ave you'll be OK. No side-trips to the close-in Maryland suburbs; again, not a lot to do and some of the neighborhoods are kind of rough. Don't miss DuPont Circle--- lots of great restaurants, nightspots and fun stuff!





And before you check into your hotel, grab a City Paper--- it's the city free weekly, comes out on Thursdays and contains all the concert/nightlife listings, restaurant ads, reviews, etc.





Enjoy your trip!
Reply:You don't need a tour package. Decide the things you are interested in, and get a Metro map. It's quite easy to get around DC on the Metro. And there is so much to see! Some take the bus tours to get a feel of what there is to see, then return to the sights they are interested in on their own later. I got a lot of good info from the Frommers website last time I went-- http://www.frommers.com/destinations/was...


I went through the list of sites, picked the ones I was interested in, and made a note of the subway stops I needed to get off at. Worked out well for me.


Here is their list of tour groups:


http://www.frommers.com/destinations/was...


We are thinking of doing the Segway tour later this month when we go.


There are also lots of hotel recommendations on the Frommers site; Washington hotels are pretty pricey...


We are staying at a B%26amp;B, the Maison Orleans.
Reply:There are so many things to see there! Definately wear comfortable shoes! Another great way is to take a short cruise on the Potomic and see the monuments from the water! That was so much fun! Have a great time!
Reply:www.vrbo.com is your best cheapest bet for great lodging
Reply:I just visited there for the first time. My wife and I stayed at the Omni Shoreham Hotel. We did priceline for the hotel got the room for $70 regularly $189. Great location. Close to the National Zoo, gotta see the pandas. Very close subway stop. We used the trolley tour, you can get on and off at a number of the popular sites. Cost is $32 a day. Taxis are very plentiful. Had dinner at Harborfront near Georgetown. Number of very nice restaurants. Enjoy DC everyone should visit our capitol. Also, wear comfortable walking shoes you will need them.


I know C and I can use it to create some intermediate level programs! I can use sockets, pointers pretty well!

But I can not make a program to calculate prime numbers or anything that has to do with math! I am really down with math! Kids in my class can make that kind of stuff with math but they can't program at all! they are good with math, I am good with C! Some people tell me that I do not need math and i should go ahead and expand my knowledge in C and othnd others tell meers! I've done that and I am still learning C and I think it is easy and I am loving it! But when at school, I have to do a simple problem with numbers, I freeze! So why do people say that if you want to be good at Programming, you must be good at math! I am a living proof that what they say is not true

I know C and I can use it to create some intermediate level programs! I can use sockets, pointers pretty well!
umm.. unless you end up in writing games or some other sorts of simulations, chances are that you will not explicitly need maths when you have to deliver code.


having said that, I have myself been a strong proponent of knowing maths (And physics) for programmers. if you dont know math, you can often deliver good code to implement a solution that was basically designed by some one else. however, you will almost never know how to compare that with a different solution.


I personally like the designing of a solution as much as coding it.. so I favour learning basic math to be able to calculate the tradeoffs.
Reply:Good with C? great!





A good programmer, ideally gets an algorithm from some place, writes the program and it works just the way the algo works. End of story. This is how vast majority of application developers live.





When you get to serious programming work, such as scientific programming or OS or compiler or toolchain development, you are pretty much on your own. Nobody knows which algorithm works best. Algorithms are taken from math!!! They are pretty much written in a mix of math and a natural language. You will have to develop algorithms. That is to say, you have to speak the language of math!





Now, depending on which of these two programmer profiles suits you best, you can choose to flirt with math or just ignore it.
Reply:i was (and still am) bad at maths, but good at programming. so it's not true what they say :)





(and i have a good job as a C programmer.)





sometimes, when i don't understand something mathematical (i.e. an algorithm), i write a program (in C or python or perl) which implements the algorithm. and then i can understand it.
Reply:Some programming is about math. Some programming is about managing information. There is some overlap and knowing both is always helpful.
Reply:yep, i have the same sentiments.... they even told me that the rationale was that if your good at math, then your good at analysis... i really disagreed! but we have to agree that being good in math does have an advantage especially in writing complicated programs.


Write a program in c language to reverse a string using pointers?

These other guys are correct - you should not just throw out homework questions without making an attempt to learn yourself. In the case we are wrong, and you are stuck altogether, here is a dirt-simple program that will do what you need. I hope you learn something from this.





-----


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





/* here is your "test" string */


/* you will probably want to read you array


* from stdin or something, but this hard-coded


* version will serve to illustrate


*/


char original_string[64] = {"Testing 1 2 3"};


char reversed_string[64];





int main (int argc, char *argv[])


{


int i;


int count;


char* output_ptr;








count = strlen(original_string);





output_ptr = reversed_string + strlen(original_string) - 1;





for(i = 0; i %26lt; count; i++)


{


*(output_ptr - i) = *(original_string + i);


}





/* verify results */


printf("Original string: %s\n",original_string);


printf("Reversed string: %s\n",reversed_string);





}

Write a program in c language to reverse a string using pointers?
Why are you asking all these questions?


Do your own homework, for crying out loud.





If you need help with something, then post your code. Otherwise, it's just rude of you to ask other people to waste their time on you.
Reply:Show us what you have so far instead of putting no effort into it at all.


In C++, Can u explain how to use pointers to call variables by reference when using classes?

Give some examples...


useful references...

In C++, Can u explain how to use pointers to call variables by reference when using classes?
This is a pretty basic question, and I suggest you get a better understanding of pointers in general because they are a key part to C/C++.





Start by reading this:


http://www.cplusplus.com/doc/tutorial/po...
Reply:CMyClass


{


public:


int m_nValue;


};





void MyFunc()


{


CMyClass MyClass;


IncValue(%26amp;MyClass);


}





void IncValue(CMyClass* pMyClass)


{


pMyClass-%26gt;m_nValue++;


}
Reply:Can I have some money now please ?

magnolia

I need some help with C++ pointer operators.?

I have a question about C++ pointer operators. What's the difference between these two operators, .* and -%26gt;*, and . and -%26gt;? I know what the dot does, but I'm not so sure about the rest of them, specifically the pointers-to-members operators. (I know they're names and Microsoft tries to explain them but it's a little confusing.) Help? Thanks.

I need some help with C++ pointer operators.?
okay. you said you know the dot operator, then, the -%26gt; operator works just the same. Except, the -%26gt; calls the member of the pointer objects. for eg, you have declared one instant of the class such as:





Student *mystudent;





where the mystudent object has become the pointer to the class Student.


Just because of this, whenever you want to access the Student class member, you need to use the -%26gt; instead of . operator, like in this line:





mystudent-%26gt;getStudent();











The same for ......-%26gt;*.......,


this really returns the pointer(i.e address) of the corresponding member being called, like in this case,





mystudent-%26gt;*getStudent();





will return the address of the getStudent value, which is stored in the system.
Reply:dude i really dont know. i only know about C

strawberry

Sunday, July 12, 2009

Im a c/c++ user, and im stuck to basic programing, i know clases,reference,pointers,ADT'... etc. i cant apply 8

how can i apply it, i mean i cant apply it to make a game, a database, a keylogger, etc. I have no reference and i think im stuck to basic programming.i usually rely to online tutorials but i cant find advance and intermediate topics. I and started to learn Visual c++ but i really dont know how to make a game? where should i start? Does everyone experience this kind of transition from basic to intermediate? thanks a lot..... Ryuuzakiii -aspiring programmer-(-,-)

Im a c/c++ user, and im stuck to basic programing, i know clases,reference,pointers,ADT'... etc. i cant apply 8
To practice swimming, you shouldn't jump right away into the ocean, pal! Try practice in small pools first.





Your first problem is your "view". It is like you know what a riffle is good for, and you know the concept of firing a gun, but in practice, it looks like a normal stick or baton to you.





First try to write short pieces of programs. Oblige yourself to forget the conventional way of programming, and try hard to find the classes and objects related to your short problem. Do it over and over until you feel you cannot do without them. Then the great ideas would come to you by themselves!





Good luck
Reply:want some resources for game programming i have few articles and source code but only in c language i you want it then mail me with subject as "c game" to


firozahmed143@rediffmail.com
Reply:I've been programming for a few years, and I'll tell you right now -- starting a game is a bit more advanced than the beginner/intermediate border.





I'd love to help with whatever your problem may be, but I think you've had some trouble posting it -- I can't exactly say I know what it means to "apply 8". Sorry.


Im a c/c++ user, and im stuck to basic programing, i know clases,reference,pointers,ADT'... etc. i cant apply 8

how can i apply it, i mean i cant apply it to make a game, a database, a keylogger, etc. I have no reference and i think im stuck to basic programming.i usually rely to online tutorials but i cant find advance and intermediate topics. I and started to learn Visual c++ but i really dont know how to make a game? where should i start? Does everyone experience this kind of transition from basic to intermediate? thanks a lot..... Ryuuzakiii -aspiring programmer-(-,-)

Im a c/c++ user, and im stuck to basic programing, i know clases,reference,pointers,ADT'... etc. i cant apply 8
here is a link where you will find C++ and visual C++ game programming resources which includes free tutorials, e-books, on-line training and many other resources.


And don't worry everyone experiences difficulties in starting.





Just follow the link and enjoy :


http://www.deitel.com/ResourceCenters/Pr...


How do you use pointers with two dimensional arrays in C++?

So I have this program that deals with one dimensional arrays. I want to expand it to two with array[row][col] how can I do this?





#include %26lt;iostream%26gt;


using namespace std;





int* getArray(int row);


void printArray(int* array, int row);





int main()


{


int row;


cout %26lt;%26lt;"Enter row length: ";


cin%26gt;%26gt;row;


int* array = getArray(row);


cout %26lt;%26lt; "array in main" %26lt;%26lt; endl;


printArray(array, row);


/*int* array2 = getArray();


cout %26lt;%26lt; "array2 in main" %26lt;%26lt; endl;


printArray(array2);


cout %26lt;%26lt; "array in main" %26lt;%26lt; endl;


printArray(array);


delete[] array2;*/


delete[] array;


return 0;


}





int* getArray(int row){


int *array = new int[row];


for ( int i = 0; i %26lt; row; i++ ){


cout %26lt;%26lt; "Enter an integer: ";


cin %26gt;%26gt; array[i];


}


cout %26lt;%26lt; "array in getArray()" %26lt;%26lt; endl;


printArray(array, row);


return array;


}





void printArray(int* array, int row)


{


for ( int i = 0; i %26lt; row; i++ ){


cout %26lt;%26lt; *(array+i) %26lt;%26lt; " ";


}


cout %26lt;%26lt; endl;


cout %26lt;%26lt; endl;


}

How do you use pointers with two dimensional arrays in C++?
Hi. I would love to help you. But, answering the question will be as long as your question. I thought that instead of giving a long answer, i could redirect you to some place where you can find good references.





http://www.cplusplus.com/doc/tutorial/


www.cplusplus.com/doc/tutorial/pointer...


www.codersource.net/c++_pointers.html





If you are still unable to find any useful information, and if there is anything specific that you would like to know, just drop in a mail to me. I shall try to help you.





Thanks! :)
Reply:u r goin right way baby
Reply:Generally speaking to access an array you use a for loop. This is for a 1 dimentional array. You want a two dimentional array.





So the way to do this is a nested for loop


ie.


for ( int i = 0; i %26lt; row; i++ ){


for ( int j = 0; j %26lt; col, j++ ){


cout %26lt;%26lt; "Enter an integer: ";


cin %26gt;%26gt; array[i][j];


}


}





That is all there is to it. You already understand the array concept. Now go ahead and extend what you know.





Good luck.


Any pointers on loosing pooch after a c-section?

you know that ugly protuding flabby skin on you lower belly...i would really love to lose it...any suggestions would be very helpful thank you

Any pointers on loosing pooch after a c-section?
chances are if you have it now, you will always have it to some degree. When you have a c section the nerves are cut, that is why you might have noticed numbness. Seven years later and my lower belly is still numb, all the nerves didn't grow back.





It reminds me of when somone has a stroke...the nerve damage causes their side of their face to droop. It is like the same thing. The nerves are cut and it droops a bit.





If you can't lose it, embrace it...it was caused by the most amazing thing that can happen to a woman in life...birth.
Reply:aerobics, and lots of toning in that area, like crunches and sit-ups. ..i think.good luck.
Reply:Well I don't know about embracing it ...but if you have that extra flab due to c section you may need some plastic surgery. If it is just fat from poor diet and exercise...that can be worked with...proper diet and regular cardio will do wonders for a body.
Reply:WELL I HAD A C-SECTION IN NOVEMBER 2004 AND THE POUCH IS HARD TO GET RID OF. BUT THEY HAVE PELNTY OR EXCERSICE EQUIPMENT TO RID IT. I HAVE THE AB LOUNGE IT SEEMS TO BE WORKING. BUT THEN THE PLASTIC SURGERY LIKE LIPO AND THE TUMMY TUCK WOULD WORK, BUT IT'S BEST TO TRY AND DO IT NATURALLY. GOOD LUCK W/ THAT I'M STILL WORKING ON MINE AND I ALSO FEEL THAT NUMBNESS AND SHARP BURNING PAINS IN THE AREA.

forsythia

Passing down objects(or pointers to them) to functions in C++?

I was wondering if it was possible to pass down either an object itself directly to a function or if I could make a pointer to an object to pass down.





Example:





testFunction(object object_name);


--or--


testFunction(object *object_pointer);





If you need me to rephrase the question, just ask. Thanks.

Passing down objects(or pointers to them) to functions in C++?
testFunction(object object_name) is possible but requires that object has a copy constructor if it is a class or struct.





testFunction(object *object_pointer) requires the caller to call the function as testFunction(%26amp;object_instance) and requires more effort in the function body.


To reference the object class, you must use object_pointer-%26gt;data or object_pointer-%26gt;function() or *object_pointer





testFunction(object %26amp;object_reference) is the recommended way to pass an object. In the function body, you just type object_reference.data or object_reference.function() to access the data and functions in the object class.


To prevent the function from returning a modified object,


use testFunction(const object %26amp;object_reference)
Reply:testFunction(object object_name) - you are passing the copy of the object, not the object itself.





testFunction(object%26amp; object_name) - now you are passing the actual object (its reference to be precise).





testFunction(object* object_name) - now you are passing the pointer to that object.





Changes made in the last two examples will affect the original object that was passed to the method. In the first example you are passing the copy, so the changes will not affect the original object.
Reply:You should use a reference to the object in question. The only way to pass an object by value is to implement a copy constructor, and then a new object would be instantiated in the stack of the called function. There is a lot of overhead associated with this, and it's generally unnecessary.





So in your calling function you would have:


testFunction( %26amp;myObject );





And your function would look like:


void testFunction( Object* theObject ){}


Can any one give me any pointers on power flushing my c/h system?

You need a power flushing machine cost approx £700, or hire one for a couple of days, (that is how long it will take if you don't know how) £75 per day plus deposit, you probably won't do it right, (half the engineers don't do it, or know how), and will have to have it done properly, it costs in excess of £600 for british gas, most others at least £200 cheaper.

Can any one give me any pointers on power flushing my c/h system?
do you really need a power flush?if you do then as some of the others have stated,it would be best leaving it to an expert.i have a machine for flushing,and it took me a while to get used to it,so even if you hire one,and buy chemicals,you could be 200 quid out of pocket and still be no further forward.
Reply:they use a special pump and chemicals ..you will never get it as clean as them
Reply:Yes! Pay someone to do it - it is a crap and messy job if you screw it up