void main()
{
char str[2][7] = {"1234567", "abcdefg"};
char** p = str;
printf("%d\n", *(p+1));
printf("%c\n", *(p+1));
}
The output is:
1631008309
5
Edit: Thank you. I see the '5' is only 0x35, other than str[0][4] I supposed to be. Why can't I get out str[0][4] instead of this strange 1631008309??
OMG, I'm foolish...
Hi,
I'm calling a C DLL function and need to supply the following C struct:
typedef struct
{
char *mTableId;
char **mFieldNames;
int mNumFields;
char *mFilter;
char *mSort;
int mOffset;
int mMaxRecords;
char *mTargetRecordFilter;
int mSurroundingRec...
Although I use std::vector almost all the time, I am interested in understanding as much as I can about pointers. Examples of what I am talking about:
char* array[5]; // What does it mean?
// 1) pointer to an array of 5 elements!
// 2) an array of 5 pointers?
I am interested in the precise definition of this declaration.
...
Why reference types and pointers are same in compiled code?(You can see in third and fourth line). I tried to figure it out but apparently I could not achieve.
If a reference type variable must be initialized at declaration and can not be changed so is there any need to do indirection as in pointers?
int x = 10;
mov dword ptr...
I have structs like this:
struct Child
{
int foo;
char bar[42];
};
struct Parent
{
long foobar;
struct Child ** children;
size_t num_children;
}
I have defined an API like this:
struct Parent * ParentAlloc() { struct Parent* ptr = (struct Parent*)calloc(1, sizeof(struct Parent));
ptr->children = (struct Child**)calloc(S...
Hello, I just started using javascript and I'm missing something important in my knowledge. I was hoping you could help me fill in the gap.
So the script I'm trying to run is suppose to count the characters in a text field, and update a paragraph to tell the user how many characters they have typed. I have an object called charCounter...
I'm learning c++ and writing a binary search tree. The following is the code I wrote for my insert method.
BSTNode * BST::Insert(const std::string & v) {
BSTNode *n = !root ? root = new BSTNode(v) : Insert_Helper(v,root);
if(n) size++;
return n;
}
BSTNode * BST::Insert_Helper(const std::string & v, BSTNode *n) {
if(!n->value.compar...
I am relatively new to C++ programming, but am a C programmer of 10 years so am more comfortable with pointers to objects than I am with references to objects.
I'm writing a Solitaire game - is this design unsafe? Is there a better way?
Anyway, I have a class SolitaireGame:
class SolitaireGame:
{
public:
SolitaireGame( in...
Hi guys, just brushing up on some C for a class and I've run across a little something that makes me scratch me head. For this code:
char * findString(const char * s){
/* Allocate space */
char * ret = malloc(strlen(s) + 1);
/* Copy characters */
char * n;
n = ret;
for ( ;*s != 0; s++)
if (isLetter(*s))
*n++ = *s;
*n = 0;
...
So pray tell, how would I go about getting the largest contiguous string of letters out of a string of garbage in C? Here's an example:
char *s = "(2034HEY!!11 th[]thisiswhatwewant44";
Would return...
thisiswhatwewant
I had this on a quiz the other day...and it drove me nuts (still is) trying to figure it out!
UPDATE:
My fault...
What makes smartpointers better than normal pointers?
...
Write pointer to string,delete pointer,and load pointer from string?
...
When I read litb answer to this question, I learned that passing an array by reference allows us to obtain its size. I just played little bit with code, and tried to pass a "function" by reference and surprisingly (at least for me), this code compiles:
void execute( void (&func)() ) // func is passed by reference!
{
func();
}
Is t...
#include<stdio.h>
#include "amicablenumber.h"
int i,j;
struct amicable
{
int **amicablePair;
int size;
};
main()
{
int startnum = 250;
int endnum = 1000;
struct amicable* ami;
ami = getAmicablePairs(startnum, endnum);
printf("{");
for(int i = 0; i<ami->size; i++)
{
printf("{%d, %d}",ami->amicablePair[i][0], ami->amicab...
Hey fellas...
OK, a recent quiz entry tasked the student with writing a method 'longhead' (char *longhead) that would return a string consisting of the concatenation of all of the heads in a given string. Example:
char *string = "this";
printf("%s\n", longhead(string));
OUTPUT: tththithis
I did come up with a solution, but it works ...
In C programming, you can pass any kind of pointer you like as an argument to free, how does it know the size of the allocated memory to free? Whenever I pass a pointer to some function, I have to also pass the size (ie an array of 10 elements needs to receive 10 as a parameter to know the size of the array), but I do not have to pass th...
Hey everyone,
I was wondering if it is possible to traverse a linked list like this:
currentNode = randomNode;//where randomNode may or may not = firstNode
prevNode = firstNode;
while(prevNode != currentNode
}
Is it possible to do this in C++ when I am trying to find the node before currentNode in a singly linked list?
I trying to...
Hey SO,
This should be easy for all you C hackers out there :D
Anyways, I want to store a 4-byte int in a char array... such that the first 4 locations of the char array are the 4 bytes of the int.
Then, I want to pull the int back out of the array...
Also, bonus points if someone can give me code for doing this in a loop... IE writi...
In below code snippet, although pointer is not initialized the call is still made successfully
temp *ptr;
ptr->func2();
Is it due to C++ language property, or it is VC++6 compiler which is foul playing?
class temp {
public:
temp():a(9){}
int& func1()
{
return a;
}
bool func2(int arg)
{
if(arg%2==0...
The code is
char** p = (char **) malloc(sizeof(char **) * size); //Where size is some valid value.
p[1] = (char*) malloc(sizeof(char) * 30);
Is the above code fine?
My understanding is
p -> +---------+
0 char* + -> {c,o,d,e,\0}
+---------+
+---------+
1 char* + -> {t,o,a,d,\0} //The assignment of these value...