C++ :: Pointer Passed Into A Function Looses Address It Points To

Mar 7, 2013

Sem is a pointer to semantic which is a struct type variable. I pass the sem into function yylex so i can fill the semantic.i and semantic.s(s points to an array). The problem is that when sem->i = a; is used inside yylex function, sem->s stops showing to the array.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <iostream>
using namespace std;
union SEMANTIC_INFO

[Code] ...

View 2 Replies


ADVERTISEMENT

C++ :: Object That Is Passed To Function Is Changed Although No Pointer Is Passed

Mar 22, 2013

I am posting this simplified piece of code that is a bit confusing for me. There are two functions that I call. One shows the expected results but the result of the other one rather puzzles me.

//#define defineVecTyp Vec3f
#define defineVecTyp float
template <typename vecTyp>
vecTyp buildLaplacianPyramid(cv::Mat inputmat) {
vecTyp lapPyr;

[Code].....

Calling the function sum1 does not change the values stored in the variables val1 and val2. The output of the program is as follows:

val1= 1 ## val2= 10 // before the call of function sum1
val1= 1 ## val2= 10 // after the call of function sum1
sumOfVals= 22

This is quite obvious and as expected and I just pasted this piece of code as an example for better clarification.

However, if I call the function buildLaplacianPyramid and apply a function for Gaussian Blurring, this also effects the cv::Mat passed to the function. The line imshow("M1, after buildLaplacianPyramid",M1); therefore shows an image that is blurred. Since I am not passing a pointer to the cv::Mat I do not understand why this should be happening. I was assuming that there would be a copy of the cv::Mat M1 to be used within the function. Therefore I was expecting the cv::Mat M1 to retain its original value. I was expecting that all changes applied to cv::Mat inputmat within the function would not have any influence on the cv::Mat M1. Just like in my other example with the sum.

View 3 Replies View Related

C++ :: Pointer Passed To Function Value Doesn't Change

Dec 24, 2014

when i pass a string pointer to a function such as string *str = new string(""); and pass that string to a handleElement() function e.g. handleElement(str), and i change the value in the function it simply doesn't change when the function exits as though it's passing it by value or something, even though it gives the pointer address.. I've now changed the code to use double pointers and pass the reference of the str pointer and it works but it seems ugly to use double pointers for this.

//handles when a new element is encountered when parsing and adds it to the parse tree
bool ParseBlock::handleElement(char cur, string *curString, int count, bool isOperator) {
countNode = new ParseNode(count);
//keep track of numbers and strings if they exist and insert them
if(!curString->empty()){
if(isNumber(*curString)

[code].....

View 2 Replies View Related

C++ :: Function Having Argument As A Pointer Passed By Reference

Dec 8, 2014

I have to write an example in which you use a function having as argument a pointer passed by reference in C++. Can you provide an example like this:

funz.h : void funz( int *&a );
funz.cpp : ? (1)
main.cpp:
#include "funz.h"
#include <iostream>

[Code]...

as I write in (1) and (2) ?

View 5 Replies View Related

C++ :: Pass Address Of Pointer To Function

Sep 25, 2014

#include <iostream>
using namespace std;
void myfunc(int* ); // what do i put in these parameters to accept a mem loc of a pointer
int main () {
int x = 5;

[Code] .....

SOLUTION:

#include <iostream>
using namespace std;
//Purpose to create a function that returns a pointer to a pointer
int** myfunc(int**);
int main () {
int x = 5;

[Code] ....

View 3 Replies View Related

C++ :: Labels As Pointer - Passing Address To A Function

Mar 7, 2014

Is there such thing as passing a winforms label by reference? For example, can I create a pointer label and pass the address to a function? I've looked online but couldn't find anything. Perhaps that's a sign?

View 1 Replies View Related

C++ :: Linked List Node Passed As Parameter / Argument Pointer To Pointer Notation

Jan 17, 2014

I was having problems changing the value of my head node I passed it as an argument as head which would be the address. The parameter was defined as struct node *head. like this

bool deleteNode(struct node *head, struct node *delptr)

I tried manipultaing pointer values to change head node value but it did not work. I saw some code online which used pointer to pointers(in code below) to change head node value it worked I dont fully understand why. Would like better understanding of why.

Would also like to know why the argument call needed &head instead of just head.

remove = deleteNode(&head,found); opposed to remove = deleteNode(head,found);

#include "stdafx.h"
#include<iostream>
struct node{

[Code].....

View 1 Replies View Related

C++ :: Get Pointer That Iterator Points To And Store In Pointer Variable?

Apr 19, 2014

I'm making a system like twitter for class called ShoutOut.com I want to be able to get the PublicShoutOut pointer pointed to by the start iterator and assign it to firstShoutOutToDisplay and secondShoutOutToDisplay because I need that in order to pass the pointers to one of my functions. When I step through the debugger the values in start are all default values like "" and so are the values in this->firstShoutOutToDisplay but the message that start points to is being output just fine.

EDIT: got rid of irrelevant code. Am I using the correct syntax to do this?

if (start != finish) {
//getting these because a shoutout needs to be passed to the function that displays
//options for a shoutout
this->firstShoutoutToDisplay = (*start);

[Code] ....

View 2 Replies View Related

C++ :: Returning Pointer That Points To Array

Mar 5, 2013

I have a program that is trying to find all factors of an integer given. It needs to be done in a recursion function. Right now i have code similar to just getting the prime factors of a integer.

unsigned int * find_factors_using_recursion(unsigned int x ) {
unsigned int * factor = new unsigned int[];//do i put x in here ?
for(unsigned int i = 2; i < x; ++i) {
if(x % i == 0) {
find_factors_using_recursion(x / i);
*factor = (factor[i] = i);
} }
return factor;
delete [] factor;
}

When i cout the *factor = (factor[i] = i) it gives me the prime numbers of the integer passed into the function but when I return the pointer it only returns one of the prime numbers. I'm new to c++, how to return pointers from functions that would be great with an example to go with it.

View 10 Replies View Related

C :: Keep Track Of Size Of Blocks Of Memory That A Pointer Points To - Malloc Is Stuck On 8

Jan 8, 2014

I'm trying to keep track of the size of blocks of memory that a pointer points to. No matter what I do, this code below always outputs the integer 8.

If I change 1000 to 5, I still get 8. If I change it to 0, I get 8... If I change it to -1, I get 8. If I change int *a to double *a, I get 8. If I take away the & symbol, I get 8. If I use *& instead, I get 8.

Why? I want it to output 1000. If I change that to 500, I want it to output 500.

int *a;
a = malloc(1000 * sizeof(int));

int j = sizeof(&a);
printf("%d", j);

I want to build my skills where I can allocate, inspect and change memory sizes.

View 4 Replies View Related

C :: Display Address Of A Pointer

Jan 31, 2014

I've got a problem with a piece of code that it doesn't seem to work anymore.

Code:
#include <stdio.h>
#include <conio.h>
main () {

[Code] ..... i

I chose a to be 5 and it displays the following:

"Type a value for a:
5
5 in octal is: 5
5 in hexadecimal is: 5

Process returned 23 <0x17> execution time : 1.031 s".I first saw this when trying to display the address of a pointer. Am i missing something? I used to run this code on dev-c++ successfully but after a day or so of practice, it's not working anymore. I switched from dev-c++ to code blocks.

View 5 Replies View Related

C++ :: Pointer (Save Address Value) To Char

Dec 9, 2013

I have a pointer to an Address is there a way to save that address value (not the content but the actual address) into a char ?

View 5 Replies View Related

C++ :: Assigning Address To Object Pointer

Aug 16, 2013

I have the following code.

StackElement *StackElementArray;
StackElementArray = new StackElement[iMaximumDepth];

I want to assign one element of this array StackElementArray the address of another object. For example,

voidStackMem::push(StackElement &iStackElement) {
CurrentDepth++;
StackElementArray[0] = iStackElement;
}

The StackElement class contains pointers to some dynamic arrays. When I use the assignment, StackElementArray[0] = iStackElement;, it doesn't copy the complete contents and I have to define an 'assignment operator' function to copy all the contents. I am wondering if there is a way I can assign StackElementArray[0] the pointer to the StackElement object. In that case, I will not need to copy the contents of iStackElement into StackElementArray[0] and will just copy the address.

View 3 Replies View Related

C++ ::  How To Store Memory Address In A Pointer

Apr 29, 2013

What I'm trying to do is:

int *p;
someType memoryLocation;
cout<<"Enter your memory location: ";
cin >> memoryLocation;
p = memoryLocation;
cout << *p;

I was just messing around with some code, and was curious to if this was possible.

View 6 Replies View Related

C :: Pointer Jumping Over Address In Uneven Array

Jan 1, 2015

Why my pointer skips over the colour addresses, it jumps to the next size address when I use Pointer++. I have tried changing the the char array to 4 bytes instead of 32 and whatnot but it doesn't work.

If I set the Pointer = the first colour address, it skips over the size addresses and only get the colour addresses. I know using 2 arrays would easily solve everything, but sadly I must use only 1.

I'll post whatever relevant code here:

View 3 Replies View Related

C :: How To Determine If Modulus 16 Of A Pointer Address Equals 0

Mar 21, 2013

For part of my program in class I have to take a pointer address and determine if it is equal to 0 modulus 16. But I can't figure it out.

View 1 Replies View Related

C :: Initialize A Pointer Variable With A Knowing Address?

Dec 28, 2013

I need to initialize a pointer variable with a knowing address. See code below, ptr is the final destination and value of ptr_address contains the address value, so I need to do something like ptr = *ptr_address.

Code:

int *ptr;
int *ptr_address;
int address;
address = 0x10000005;
ptr_address = &(address);
ptr = *ptr_address;

The problem is that compiler gives the following warning message:

warning: assignment makes pointer from integer without a cast [enabled by default]

Is my code wrong or there is any other way to do it without receiving this compiler warning?

View 3 Replies View Related

C++ :: Integer Pointer - Get Address Without Allocating Memory

Jun 3, 2013

I have an integer pointer and i want its address without allocating memory,

main() {
int *a;
cout<<a;
}

This is giving 00000000 and its but obvious. Now if i use address of a (&a) along with *a,

main() {
int *a;
cout<<a;
cout<<&a;
}

'cout<<a' gives me a constant address but 'cout<<&a' gives me different address.

what is the reason behind & and why behaviour of 'cout<<a' changes when using with &.

View 8 Replies View Related

C++ :: Add Variable Address To Void Pointer Inside Of Class?

Dec 1, 2013

How can I add the variable adress to a void pointer inside of a class?

class variant2 {
private:
void *Vvariant=NULL;
public:
template<typename b>
variant & operator = (b *adress)

[Code] ....

if possible i want avoid the '&' when i assign the variable address.(variant2 f=varname;//like you see i don't use the '&')
for the moment i just need put the address to Variant pointer. but i receive several errors .

View 4 Replies View Related

C/C++ :: If Statement To Check Matching Word To Pointer Address Value

Jan 3, 2015

I'm having an issue coming up with an if() statement to check if a word match the one in the value of a pointer's address. So far the best I've come up with only matches the first letter of the words, you'll find it in the code below.

#include"Header.h"
int Colour(struct MyStruct *ArrayPointer, int ArraySize) //ArraySize = 3 for this run. {
int ColourCount = 0;
for (int i = 0; i < ArraySize; i++) {

[Code] ....

An example run you can see in attached pic.

I want to have an if statement that only accepts "Red" and not the occasional "Ravaged_Anus".

I'm using MVS Express 2013, .c source files, and the C++ compiler.

Attached image(s)

View 3 Replies View Related

C++ :: Function Passed By Pointers Or Reference?

Sep 28, 2014

I am going to read some codes about image processing and I need to understand functions like this one below?

BOOL Trans_Geo_Affine(CImage *pImgSrc, CImage *pImgDst, BOOL bMatrix,
BOOL bHvInversed, double fScale_xx, double fFlex_xy, double fSkew_yx,
double fRotate_yy, double fTx, double fTy, int nInterpolation, BOOL bResize, BYTE cFill)

[URL]

two parameters, CImage *pImgSrc and CImage *pImgDst. I think they are class pointers and the function is passed by reference. What should I learn to understand this function and its parameters? How should I use this function? how to use the function with two parameters CImage *pImgSrc and CImage *pImgDst.

View 11 Replies View Related

C/C++ :: Values Passed To Put Function But Not Having Any Effect

Feb 9, 2015

I have this code:

tgaManager.fileWriter.put((unsigned char)min(blue*255.0f,255.0f)).put((unsigned char)min(green*255.0f, 255.0f)).put((unsigned char)min(red*255.0f, 255.0f));

that should pass the value decided by the min function to an ofstream object, filewriter, that call the put method to print chars in a tga image file. When I open the file, all I see it is a huge black screen. You may be thinking that the values of blue,green and red are all zero but it is not the case.

With this code:

if (x==50 && y==50) {
cout << "Min BGR: " << endl;
cout << min (blue*255.0f,255.0f) << ' ' << min (green*255.0f,255.0f) << ' ' << min (red*255.0f,255.0f) << ' ' << x << ' ' << y << endl;

I get: Min BGR: 9.54167 29.9188 47.8701 50 50

View 3 Replies View Related

C++ :: Cloning Object Passed By Function?

May 21, 2014

Is it correct for me to make a clone of testobj in function AddTest below, before i add it to my map? What i want is an user pass testobj to me though AddTest, and after i add it into my map, i do not want to have anything to do with the original testobj anymore. I.e, they are two copies, one belong to Device, one belong to the caller, both has no link to each other.

Also regarding the GetTest method, i prefer to return a raw pointer, as i do not want to force the caller to use smart pointer. And i also do not want the caller to be able to do anything that may change testobj in the map. So i am not sure to return as const reference or make a clone of testobj on the map and return it to the user (but caller need to delete the testobj when it is not used).

Code:

class Device {
public:
void AddTest(const Test* const testobj) {
_pTest.insert("ss", QSharedPointer<Test>(test->clone()));
} const Test* const GetTest(QString str) {
return _pTest[str].data();

[code].....

View 6 Replies View Related

C++ :: Variadic Function - Parameters Get Passed In Reverse

Nov 17, 2014

I noticed that when using variadic functions, if I pass the va_arg() as parameter to a function, the parameters get passed in reverse. Is that expected?

For example, the following code outputs
Code:
1 2
2 1

Code:
#include <iostream>
#include <stdarg.h>

void foo_func(int v1, int v2)
{
std::cout << v1 << " " << v2 << std::endl;

[Code] .....

View 3 Replies View Related

C++ :: Function To Find Out How Many Days Have Passed Since Last Birthday

Feb 20, 2013

I have to write a c++ program with my own function which consists of two parameters (day, month). Function have to return number of days since the begining of this year. Using this function i have to find out how many days are left till birthday (or how many days have passed since last birthday)

This is how far i am:

Code:

#include <iostream>
using namespace std;
int cikDienu(int diena, int menesis);
int main()

[Code] ....

View 9 Replies View Related

C++ :: Global Arrays - Passed By Reference To Function

Mar 9, 2013

I currently have multiple functions that use globally declared arrays in my code.

I want to turn them so that arrays are no longer globally declared, but instead are passed by references to the function.

And I have a function caller inside main, and other functions are called within the function.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved