// Sparse Array Assignment.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
using namespace std;
struct node{
int row;
int col;
int value;
node* next_in_row;
node* next_in_col;
};
class MultiLinkedListSparseArray {
private:
char *logf...
typedef struct queue {
int q[max];
int qhead;
int qrear;
} queue;
void init_queue(queue *QUEUE)
{
QUEUE.qhead = 0;
QUEUE.qrear = -1;
}
void enqueue(queue *QUEUE,int data)
{
QUEUE.qrear++;
QUEUE.q[QUEUE.qrear] = data;
}
int process_queue(queue *QUEUE)
{
if(QUEUE.qhead > QUEUE.qrear)
return -1;
else
return Q...
I have written a class to help save and load data for the sake of persistence for my iPhone application but I have a problem with some NSUIntegers that I'm passing across.
Basically, I have the code to use pointers, but eventually it has to start out being an actual value right? So I get this error
warning: passing argument 1 of 'getSa...
I'm trying to create a set of overloaded templates for arrays/pointers where one template will be used when the compiler knows the size of the array and the other template will be used when it doesn't:
template <typename T, size_t SZ>
void moo(T (&arr)[SZ])
{ ... }
template <typename T>
void moo(T *ptr)
{ ... }
The problem is that wh...
The Size of pointer depends on the arch of the machine.
So
sizeof(int*)=sizeof(int) or sizeof(int*)=sizeof(long int)
I want to have a custom data type which is either int or long int depending on the size of pointer.
I tried to use macro #if, but the condition for macros does not allow sizeof operator.
Also when using if-else, typed...
What does it mean when a object has 2 asterisks at the beginning?
**variable
...
Why do this work?
int *var;
while(scanf("%d", &var) && *var != 0)
printf("%d \n", var);
While this does not?
int *var;
while(scanf("%d", &var) && var != 0)
printf("%d \n", var);
Doesn't * (dereference operator) give you the value pointed by the pointer? So why does
*var != 0 crash the program, while var != 0 d...
Hi,
I am a teaching assistant of a introductory programming course, and some students made this type of error:
char name[20];
scanf("%s",&name);
which is not surprising as they are learning... What is surprising is that, besides gcc warning, the code works (at least this part). I have been trying to understand and I wrote the followin...
Ok my C is a bit rusty but I figured I'd make my next(small) project in C so I could polish back up on it and less than 20 lines in I already have a seg fault.
This is my complete code:
#define ROWS 4
#define COLS 4
char main_map[ROWS][COLS+1]={
"a.bb",
"a.c.",
"adc.",
".dc."};
void print_map(char** map){
int i;
for(i=0;...
I have a very simple C++ code here:
char *s = new char[100];
strcpy(s, "HELLO");
delete [] s;
int n = strlen(s);
If I run this code from Visual C++ 2008 by pressing F5 (Start Debugging,) this always result in crash (Access Violation.) However, starting this executable outside the IDE, or using the IDE's Ctrl+F5 (Start without Debuggin...
int* p = 0;
int* q = &*p;
Is this undefined behavior or not? I browsed some related questions, but this specific aspect didn't show up.
...
My task is as follows :
Using pointers to class fields, create menu allowing selection of ice, that Person can buy in Ice shop. Buyer will be charged with waffel and ice costs.
Selection of ice and charging buyers account must be shown in program.
Here's my Person class :
#include <iostream>
using namespace std;
class Iceshop {
...
class Node
{
string name;
Node previous;
};
Error: Node::previous uses "Node" which is being defined.
How can I get this to work in C++? It works in C#.
EDIT:
Why Node* previous works?
...
The following piece of code gives a segmentation fault when allocating memory for the last arg. What am I doing wrong? Thanks.
int n_args = 0, i = 0;
while (line[i] != '\0')
{
if (isspace(line[i++]))
n_args++;
}
for (i = 0; i < n_args; i++)
command = malloc (n_args * sizeof(char*));
...
I'll illustrate my question with code:
#include <iostream>
void PrintInt(const unsigned char*& ptr)
{
int data = 0;
::memcpy(&data, ptr, sizeof(data));
// advance the pointer reference.
ptr += sizeof(data);
std::cout << std::hex << data << " " << std::endl;
}
int main(int, char**)
{
unsigned char buffer[] = { 0...
Can an unreleased COM pointer to an external process (still alive) cause that process to hang on destruction?
Even with TerminateProcess called on it?
Process A has a COM interface pointer reference to Process B, now Process B issues a TerminateProcess on A, if some COM interface pointer to Process B in Process A is not released proper...
Hello,
I am trying to improve my knowledge on program architecture and recently arised a question to me which is related with this pointers issues I posted recently.
The thing is that in a simple hierarchy in which you have Class A with a pointers to Class B and the last to Class C. Do not confuse the with the inheritage property of th...
Hi,
I want to open a text file (see below), read the first int in every line and store it in an array, but I get an segmentation fault. I got rid of all gcc warnings, I read through several tutorials I found on the net and searched stackoverflow for solutions, but I could't make out, what I am doing wrong.
It works when I have everythi...
Why is dereferencing called dereferencing?
I'm just learning pointers properly, and I'd like to know why dereferencing is called that. It confused me as it sounds like you are removing a reference, rather than going via the pointer to the destination.
Can anyone explain why it is called this?
To me something like destination or pointe...