C/C++ :: Result Is Returning Address In Memory
Jun 30, 2014
The results of my code is supposed to be very simple: return the 2 integers and then their sum. However, it's doing returning the first value, then an address in memory(rather than the 2nd value), and then the 2nd value(rather than the sum). Here is the code:
#include <stdio.h>
#include <stdlib.h>
struct calculator{
double num1;
double num2;
double result;
[Code] .....
View 4 Replies
ADVERTISEMENT
Nov 2, 2013
why my application actually crashes after it compute the area of a cross.
I output is correct but it crashes after it calculation is done.
cross.cpp
void Cross::setCrossCord()
{
for (int i=0; i<=12; i++)
[Code]....
View 2 Replies
View Related
Jul 9, 2014
I know that this code is wrong because it returns the address of local variable which no longer exist after function:
int *f1()
{
int x = 2;
return &x;
}
However, why this one does not show problem and runs fine, here the pointer p is also a local variable:
int *f2()
{
int x = 2;
int *p;
p = &x;
return p;
}
View 6 Replies
View Related
Mar 8, 2015
Code:
charArr = new char[50];
cout << "put in value: ";
cin.getline(charArr, 50);
some_func(charArr);
[Code] ....
Let's say I enter a value: 101
It goes into the if statement but clearly I've enter 1s and 0s. When I debugged, at i = 0, the charArr[i] gives me a value of 49 when assigned to an int variable. But when I cout charArr[i] it gives me 1.
So I'm going to assume 49 is part of the address? How can I correctly check the if statement condition?
View 4 Replies
View Related
Aug 10, 2014
If I do this:
void* testPtr = malloc ( 1000 )
And then this:
testPtr = realloc ( testPtr, 500 )
Will the realloc just reduce the allocated size and keep the same pointer, or can there be a chance of it finding another place for that allocation ( Meaning that it will expensively move the memory to another location )?
I am trying to create efficient programs by making my dynamic allocations the least resource hungry as possible during runtime.
View 2 Replies
View Related
Jul 12, 2013
In the code below. I believe I am returning the memory location of the value I am looking for. How can get the value?
main.cpp
int choice = 0;
PlayerMenu *newPM = new PlayerMenu;
File *file = new File;
// Menu for loading, creating or exiting the game
choice = newPM->menuChoices();
PlayerMenu.cpp
[Code] ....
I am not sure how to deference the value so I can get at the value instead of the memory location.
View 5 Replies
View Related
Mar 16, 2014
I'm trying to get the current time for a game and print that to the games chat window. I'm already injected into the process do I don't think I need ReadProcessMemory.
The value i'm trying to read is the game hours 1-12.
//doesn't work
byte time_hour_get ( void )
{
return *( byte *)0x00B70153; //the address to the memory containing the
}
addMessageToChatWindow((char*)time_hour_get); -> when I call this function it looks like s , . I want it to return the integer value like cheat engine. I used byte when scanning for this address
View 1 Replies
View Related
Nov 20, 2012
I have written a C program without variable. And I want to print the value at that memory location.How to print that value?
code is like:-
int main()
{
printf("Enter value:");
scanf("%d",1245024);
/* how to print the value here */
return 0;
}
View 8 Replies
View Related
Jan 14, 2014
I am working on something that requires the memory address of my computers workload.. collect the trace files? and what trace file as well..
View 2 Replies
View Related
Sep 30, 2013
Pointers point to an address in memory. What if I used 3 pointers: 2 to mark the first/last nodes, and the third to mark the current node being referenced? I would wrap it in a class (to make the memory management automatic, of course), but is this practical?? maybe some pseudo code will get the juices flowing:
template<class type>
class supercondensed_list{
public:
supercondensed_list();
~supercondensed_list();
[code].....
Any things I should take into consideration? I'm not exactly the most experienced with pointers, and manually managing memory, but I think it's worth trying. If this works, then my programs should, in theory, be 100% memory efficient.
View 7 Replies
View Related
Sep 9, 2013
I've recently been reading tutorials on arrays and their aquaintance with memory addresses. So, I completely understand how an array's name, when defined, is a constant pointer to its first element's address.
My problem, however, lies with characters, and how they are basically arrays except with a null terminator for the last index. What I've come to undestand, is that, when defining a character variable, each 'character' has a memory address it is associated with.
For example:
char name[] = {"Hello"}; // | 'H' | 'e' | 'l' | 'l' | 'o' | '/0' |
An address holds the value of 'H'.
An address holds the value of 'e'.
An address holds the value of 'l' and so on.
I have come to believe this is false, however. Mainly from a simple std::cout command.
std::cout << &name << std::endl; // attempt 1
std::cout << &name[0] << std::endl; // attempt 2
The first attempt, as I assumed, should print the address of the first element.
The second attempt, as I assumed, did not. I figured, &names[0] would print the address of the first element, which should have been the same as &names.
So, this brings me to my question, are characters formed of constant addresses, or are the address of individual characters not reachable?
View 9 Replies
View Related
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
Sep 12, 2013
I made a text file. I can do all File I/O functions in c. no problem! except that "I want to get the memory address of the beginning of that File", so that I can access each character of the file by incrementing memory address.
View 1 Replies
View Related
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
Jan 2, 2013
A special hardware unit with some storage in it is connected to your computer and is memory-mapped so that its storage is accessible in the address range 0x55500000 – 0x555fffff. You want to interface this hardware unit to your C++ program so that dynamic memory is allocated in this hardware unit, not in your computer’s memory. Implement a class MyHardwareMemAllocator which has the following function.
void * allocMemoryInMyHardware(int numberOfBytesToAllocate);
which returns a pointer to the allocated memory chunk, or null if unable to allocate.
C library calls like malloc are not allowed.
1) How to allocate memory from given address range.
2) How to check whether this required memory space is available or not for allocating
View 4 Replies
View Related
Jun 22, 2013
Suppose I have two classes, MyClassX and MyClassY, each with two member variables, as defined below. I create an object instance of each class, and then create a pointer to each member variable for each object:
Code:
class MyClassX
{
public:
int a;
double b;
MyClassX(int _a, double _b)
[code]....
After converting the hexadecimal to decimal, it appears that with MyClassX, pxb is 8 bytes from pxa, whereas for MyClassY, pya is only 4 bytes from pyb. This makes sense for MyClassY, because the first member variable to be stored is an int, and so will occupy 4 bytes. However, why should this be any different for MyClassX, which also has an int as the first member variable, so shouldn't this also occupy 4bytes?
The reason I have come across this problem is that I am looking into streaming objects to memory and then loading them again. (I know boost can do this, but I am trying it out myself from scratch.) Therefore, this is causing an issue, because I cannot just assume that the size of memory occupied by an object is just the sum of the sizes of its member variables. MyClassX is 8 bytes larger than MyClassY, even though the intuition is that it should only occupy 4 bytes more due to a double being replaced by an int.
View 4 Replies
View Related
Jul 8, 2014
When declaring char array[10], memory is allocated for 10 1-bit memory locations. Is extra memory allocated for storing the address of array[0]? In expressions, is array equivalent to a pointer constant or is it an identifier for a memory cell containing the address of array[0]? In other words, is array a variable or an alias for &array[0]?
View 6 Replies
View Related
Jul 26, 2012
Try to implement overloading << operator. If I done it void then everything work fine (see comment out) if I make it class of ostream& then the operator return to me some memory address.
Code:
#ifndef Point_HPP // anti multiply including gates
#define Point_HPP
#include <sstream>
class Point {
private:// declaration of private data members
double x;// X coordinate
double y;// Y coordinate
[Code] .....
View 7 Replies
View Related
Apr 30, 2013
Code:
void search(){void output(void);
char title[20],;
char *p;
clrscr();
[Code] ......
Info:Program that stores information about reports .the above function searches the report according to its title. list is the name of the structure that stores the records.
Why i'm using strstr:
for eg. there is a report titled 'report on tigers'
I want the report information to be output if someone searches for 'tiger'
Output:displays all the entries i have made till now
file is attached.
View 4 Replies
View Related
Dec 4, 2014
I'm trying to understand the pass by value-result. The code I have came up with so far only does by value and by reference, which I understand. The value-result is what has me stumped, and honestly I am unsure how to write the function for it. Here's my code so far...
#include <iostream>
using namespace std;
// Function prototypes.
void swapByValue(int, int, int);
void swapByRef(int&, int&, int&);
[Code] ....
View 4 Replies
View Related
Jul 24, 2013
I keep getting an undesired value in this code. I've tried several methods, but none are giving me the correct answer. The out put is always zero, when in this case it should be 10!!
Here's the object structure:
template<class T, class _b>
struct quantity {
private: T value;
public:
explicit quantity(T val): value(val) {};
T getValue() { return value; };
[Code] .....
Here's the operation:
int main() {
quantity<int, bool> m(20);
quantity<float, bool> m_f(10);
quantity<double, bool> m_d(NULL);
m_d = m_f;
[Code] .....
Why does it seem that the assignment operator is the harder operator to overload? Maybe it's just my luck, but I seem to always run into issues whenever I work with it. I hardly ever experience errors when overloading any of the other operators.
View 6 Replies
View Related
Nov 6, 2014
I am trying to make the code below display the result with decimals. I tried using setprecision, but I am not too sure where to put it. I placed it in cout section where the answer is but it still doesn't come out correctly.
#include <iostream>
using namespace std;
//*Delcare function prototype*
int ConvertToCentimeters (double, double );
//declare exception class*
class NegativeNumber
[Code] ....
View 4 Replies
View Related
Apr 20, 2013
typedef struct Element Element;
struct Element {
char x;
double* y;
[Code] .....
This one with y pointer gives 8
typedef struct Element Element;
struct Element {
char x;
double y;
[Code] ....
This one with a normal y variable gives 12
View 7 Replies
View Related
Nov 19, 2014
how to use the result of an if statement in my program. I'm writing a program for a knockout tournament, so i want to extract the winner of each match to carry forward in the code for use in the next round. I've tried assigning another variable (#define r1w1) and saying that the variable = cName[0] or cName[1] in the if statements like this: (i did this because i thought i could then use r1w1 later in the code)
if(scorea1 > scoreb1) {
printf("
");
printf("WINNER OF ROUND 1 MATCH 1 IS %s
", cName[0]);
cName[0] = r1w1
[Code].....
View 1 Replies
View Related
Oct 21, 2014
I am creating a program that allows the user to enter the number of days worked and calculates the amount of money gained by doubling the amount from the previous day, starting with .01 cents. The program works fine except for in day 3, the program adds .01 along with doubling the amount from day 2. Also I must use a List Box.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
[code]....
View 3 Replies
View Related
May 5, 2013
i need to know, that how i can get search result in bold format(using sequential search technique) from an array, in C++ graphic mode ???
e.g.
here is an array : 2 4 5 34 0 -45
and search key == 34
when it found 34 in array, '34' should bold to be prominent.
View 3 Replies
View Related