In the following code, both amp_swap() and star_swap() seems to be doing the same thing. So why will someone prefer to use one over the other? Which one is the preferred notation and why? Or is it just a matter of taste?
#include <iostream>
using namespace std;
void amp_swap(int &x, int &y)
{
int temp = x;
x = y;
y = temp;...
func()
{
Object* pNext;
func1(pNext);
}
func1(Object* pNext)
{
pNext = Segement->GetFirstPara(0);
}
I was expecting it to be pointer to firstpara returned from func1() but I'm seeing NULL can some explain and how to fix it to actually return the firstpara() pointer?
...
Is it possible to initialize an array of pointers to structs?
Something like:
struct country_t *countries[] = {
{"United States of America", "America"},
{"England", "Europe"},
{"Ethiopia", "Africa"}
}
I want to do that in order to get the entities in not-contiguous memory, and the pointers to them in contiguous mem...
I was trying to understand something with pointers, so I wrote this code:
#include <stdio.h>
int main(void)
{
char s[] = "asd";
char **p = &s;
printf("The value of s is: %p\n", s);
printf("The direction of s is: %p\n", &s);
printf("The value of p is: %p\n", p);
printf("The direction of p is: %p\n", &p);
p...
This question was inspired by a similar question: How does delete[] “know” the size of the operand array?
My question is a little different: Is there any way to determine the size of a C++ array programmatically? And if not, why? Every function I've seen that takes an array also requires an integer parameter to give it the size. But...
This was an job placement interview I faced. They asked whether we can realloc Array, I told yes. Then They asked - then why we need pointers as most of the people give reason that it wastes memory space. I could not able to give satisfactory answer. If any body can give any satisfactory answer, I'll be obliged. Please mention any situat...
Can standard pointers in .Net do this? Or does one need to resort to P/invoke?
Note that I'm not talking about object references; I'm talking about actual C# pointers in unsafe code.
...
I am new to C and i have this question. why does the following code crash:
int *a = 10;
*a = 100;
...
In the following case I'm calling a Func with pointer passed to it, but in the called function, the parameter shows the pointer value as something totally bogus. Something like below.
bool flag = Func(pfspara);--> pfspara = 0x0091d910
bool Func(PFSPARA pfspara) --> pfspara = 0x00000005
{
return false;
}
Why does pfspara change t...
I know it, forgets it and relearn it again. Time to write it down.
...
On an embedded target I use far pointers to access some parts of the memory map.
near pointer (without explicitely specifying __near):
unsigned int *VariableOnePtr;
Pointer to near pointer: unsigned int **VariableOnePtrPtr;
far pointer: unsigned int *__far VariableTwoPtr;
What is the correct way to declare a pointer to a far point...
I was shown this recently, and thought this was a really cool piece of code. Assume 32-bit architecture.
#include <stdio.h>
int main(void) {
int x[4];
printf("%p\n", (void*) (x));
printf("%p\n", (void*) (x + 1));
printf("%p\n", (void*) (
printf("%p\n", (void*) (
}
Without compiling the program, what does it output...
Hi friends,
I am Manoj here to ask a question again.
In C and C++ what do the following declarations do?
const int * i;
int * const i;
const volatile int ip;
const int *i;
Are any of the above declarations wrong?
If not what is the meaning and differences between them?
What are the useful uses of above declarations (I mean in whic...
I am working on implementing tail for an assignment. I have it working correctly however I seem to be getting an error from free at random times.
I can't see, to track it down to a pattern or anything besides it is consistent.
For example if I call my program as "tail -24 test.in" I would get the the the incorrect checksum error at the...
I've allocated an "array" of mystruct of size n like this:
if (NULL == (p = calloc(sizeof(struct mystruct) * n,1))) {
/* handle error */
}
Later on, I only have access to p, and no longer have n. Is there a way to determine the length of the array given just the pointer p?
I figure it must be possible, since free(p) does just that. ...
I keep reading that, in C, using pointer arithmetic is generally faster than subscripting for array access. Is this true even with modern (supposedly-optimizing) compilers?
If so, is this still the case as I begin to move away from learning C into Objective-C and Cocoa on Macs? (As is the primary goal of my picking up C -- get enough th...
What is the difference between int *a[3] and int (*a)[3]?
...
Can we call functions using function pointer? if yes how?
...
how to use array of function pointers in c?
how to initialize them?
...
This is kind of a beginners question, but I haven't done C++ in a long time, so here goes...
I have a class that contains a dynamically allocated array, say
class A
{
int* myArray;
A()
{
myArray = 0;
}
A(int size)
{
myArray = new int[size];
}
~A()
{
// Note that as per MikeB's...