If I declare a pointer to a struct in .h for example:
my_struct_t *ptr;
... and then I check if(ptr==NULL) in the code, without actually setting ptr to NULL or allocating memory for it, can I do that check to see if its equal to NULL?
essentially what I'm asking is, by having ptr in the .h, does it get set to NULL automatically, or d...
I'm having trouble with some of the pointer/array notation used. I have two lists and am sorting them, and then try to display them. I had 3 comments in my code below as to what the declarations are and why. My code looks like:
int Compare(const void *a, const void *b);
void SortStudents(char *studentList[], size_t studentCount)
{...
I am implementing the standard bubble sort algorithm, and I had a question on pointers.
float *SortValues(float *p, size_t n)
{
float temp;
float didSwap;
float *current;
float *last = &p[n - 1];
float *start = p;
do
{
for (didSwap = 0, current = p; current < last; current++) {
if (curre...
For pointers, I'm getting confused with declarations and function parameters on when to use char ** or char * or *array[n], etc. Like if a function takes a (*array[n]) parameter, do I pass it a **type?
I try using the Right-Left rule and know that p would be a pointer to a pointer to a char (char **p), and p is an array of n pointers...
Memory access through pointers is said to be more efficient than memory access through an array. I am learning C and the above is stated in K&R. Specifically they say
Any operation that can be achieved by array subscripting can also be done with pointers. The pointer version will in general be faster
I dis-assembled the following ...
ok so if we have a char *hello - ands the string is "hello"
and i do
char *ptr ;
ptr = hello;
then ptr will be pointing at 'h', correct?
Now i have just done an assignmnet in this and completed it using the following terms
if i wanted to move the pointer to the next chatachter i would just do ptr++. If i wanted to use the value of...
Using pointer arithmetic, it's possible to assign characters from one array to another. My question is, how does one do it given arbitrary start and stop points?
int main(void)
{
char string1[] = "something"; //[s][o][m][e][t][h][i][n][g][\0]
int start = 2, count = 3;
char string2[10] = {0};
char *ptr1 = &string1[start];...
For instance:
#include <stdio.h>
void why_cant_we_switch_him(void *ptr)
{
switch (ptr) {
case NULL:
printf("NULL!\n");
break;
default:
printf("%p!\n", ptr);
break;
}
}
int main(void)
{
void *foo = "toast";
why_cant_we_switch_him(foo);
return 0;
}
gcc ...
I am reading a book and it mentions certain data type as being long pointer. Just curious about what that meant. Thanks.
...
The documentation for the InterlockedExchangePointer Function states:
On a 64-bit system, the parameters are 64 bits and the Target parameter must be aligned on 64-bit boundaries; otherwise, the function will behave unpredictably. On a 32-bit system, the parameters are 32 bits and the Target parameter must be aligned on 32-bit bounda...
Hi!
I know this won'T work because the variable x gets destroyed when the function returns:
int* myFunction()
{
int x = 4; return &x;
}
so how do I correctly return a pointer to something I create within the function, and what do I have to take care with? How do I avoid memory leaks?
I've also used malloc:
int* myFunction2()
{
...
Possible Duplicate:
Difference between pointer variable and reference variable in C++
I am reading about the book "Inside the C++ Object Model" by Stanley Lippman. What puzzles me is the difference between a "reference" of an object and a "pointer" to an object. I know that a reference must be initialized when declared, while ...
I'm just learning c++, and coming from c, some function calls I'm seeing in the book confuse me:
char a;
cin.get(a);
In C, this couldn't possibly work, if you did that, there would be no way to get the output, because you are passing by value, and not by reference, why does this work in c++? Is referencing and dereferncing made implic...
Hey,
I'm pretty new to c#, and i'm trying to understand something pretty basic.
I want to implement a RBTree and a linked list , so i create :
public class RBTreeNode
{
// PROPERTIES
public RBTreeNode left;
public RBTreeNode right;
public RBTreeNode parent;
public String Color;
public In...
Isn't a pointer just a reference when you don't de-reference it?
#include "stdafx.h"
#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>
std::list<int>* user_defined_func( ) {
std::cout << "BEGIN: user_defined_func" << std::endl;
std::list<int>* l = new std::list<int>;
l->push_back(8);
l->pu...
I have a question. I have the following struct:
typedef struct{
int vin;
char* make;
char* model;
int year;
double fee;
}car;
Then I have the following method that asks the user for the make of a car and returns it as a char pointer
char* askMake(){
char* tempMake = NULL;
cout << "Enter Make:" << endl;
...
I have the following struct:
typedef struct{
int vin;
char* make;
char* model;
int year;
double fee;
}car;
Then I create a pointer of type car
car *tempCar;
How do I assign values to the tempCar? I'm having trouble
tempCar.vin = 1234;
tempCar.make = "GM";
tempCar.year = 1999;
...
I am sorting my array of car two ways. one by year which is shown below. and another one by make. Make is a char* How do I compare char pointers?
int i, j;
for(i=0; i<100; i++){
for(j=0; j<100-i; j++){
if(carArray[i]!=NULL && carArray[j]!= NULL && carArray[j+1]!=NULL){
if(carArray[i]->year > carArray[j+1]->year...
After reading a description about swapping pointer addresses on Stackoverflow, I have a question about C++ syntax for references.
If you have a function with the following signature:
void swap(int*& a, int*& b)
What is the meaning of int*& ? Is that the address of a pointer to an integer? And furthermore being that it is a pointer re...
Hi!
I got a hw assignment asking me to invoke a function without explicitly calling it, using buffer overflow. The code is basically this:
#include <stdio.h>
#include <stdlib.h>
void g()
{
printf("now inside g()!\n");
}
void f()
{
printf("now inside f()!\n");
// can only modify this section
// cant call g(), maybe...