logo
down
shadow

Not understanding pointer


Not understanding pointer

By : tangshan
Date : November 21 2020, 04:03 PM
I think the issue was by ths following , Your pointer are not initialized, they need to point to valid memory using malloc or by taking address of a local variable.
code :
#include <stdio.h>
int main()
{
    int p, q;
    int *pp = &p;
    int *pq = &q;
    *pp=5;
    *pq=6;
    printf("%d %d", *pp, *pq);
    return 0;
}


Share : facebook icon twitter icon
Pointer to pointer array understanding problem

Pointer to pointer array understanding problem


By : Mark David
Date : March 29 2020, 07:55 AM
hope this fix your issue Is your misunderstanding that you think you have created a pointer to an array of 7 int? You haven't. You actually have created an array of 7 pointers to int. So there is no "second pointer" here that would point to an array. There is just one pointer that points to the first of the 7 pointers (test).
And with *test you get that first pointer which you haven't initialized yet, though. If you would add 1 to that, you would add 1 to some random address. But if you add 1 to test you get a pointer that points to the second pointer of the array. And dererencing that you get that second pointer, which you did initialize.
code :
typedef int array[7];
array* test = new int[1][7];

// Note: "test" is a pointer to an array of int. 
// There are already 7 integers! You cannot make it
// point to an int somehow. 
*(*test + 1) = 7;

int *p1 = *test
int i1 = *(p1 + 1); // i1 is 7, second element of the int[7]

delete[] test;
int(*test)[7] = new int[1][7];
Understanding pointer to pointer concept

Understanding pointer to pointer concept


By : user3360145
Date : March 29 2020, 07:55 AM
it fixes the issue I am a begineer in C and I am trying to understand pointer to pointer concept. I have the following example , Here is how I read it:
code :
// (char*) is an address (of char): 8 bytes
(char *)  names = 0x7fff167f7c00 // actual address of names

// (char**) is an address (of char*): 8 bytes
(char **) names = 0x7fff167f7c00 // actual address of names.

// *(char*) is a char: 1 byte.
*(char *) names = 0x58           // first byte of the first value of names (ie address of "Peter").

// *(char **) is an address (of char): 8 bytes
*(char **)names = 0x400658       // first value of names (ie address of "Peter").
Understanding pointer to pointer arrays as arguments in a function

Understanding pointer to pointer arrays as arguments in a function


By : Ales Daniel
Date : March 29 2020, 07:55 AM
may help you . While trying to learn C by myself, I came across this simple program that I want to develop. It just tries to make use of pointer to pointer arrays to make something that resembles matrices. I'm compiling on Windows and when I run it, it just crashes, meanwhile, trying this code on Linux it says segmentation fault, is this because of the function arguments that are arrays? What am I doing wrong here? , when doing:
code :
void initializeArray(float** array, int size)
{
    array = malloc(size * sizeof(float*));
float **initializeArray(int size)
{
    float** array = malloc(size * sizeof(float*));
   ...
    return array;
}
array_1 = initializeArray(array_size);
understanding pointer to a structure refers to pointer member in c in accessing it

understanding pointer to a structure refers to pointer member in c in accessing it


By : Peter Hamilton
Date : March 29 2020, 07:55 AM
this one helps. I have a below program and compilation is success but while running,program crashes in eclipse , Create a Student structure, allocate it and use it
code :
typedef struct Student
{
   unsigned int  *ptr;  //Stores address of integer Variable
} Student;

int main()
{
    Student *s1;
    unsigned int roll = 20;
    s1 = malloc(sizeof(Student));
    if (s1 == NULL) {
        return -1;
    }
    s1->ptr   = &roll;

    printf("\nRoll Number of Student : %d",*(s1->ptr));
    free(s1);

    return(0);
}
Simple function-size; Understanding pointer-pointer difference

Simple function-size; Understanding pointer-pointer difference


By : Rishabh Rawat
Date : March 29 2020, 07:55 AM
should help you out Pointer arithmetic in C/C++ is designed for accessing elements of an array. In fact, array indexing is merely a simpler syntax for pointer arithmetic. For example, if you have an array named array, array[1] is the same thing as *(array+1), regardless of the data type of the elements in array.
(I'm assuming here that no operator overloading is going on; that could change everything.)
Related Posts Related Posts :
  • (Conditional?) creation of local variables in function
  • Is it possible to count the function (variable) arguments in a __cdecl with Inline ASM?
  • Does C guarantee 32-bit integer arithmetic?
  • format specifier inside format specifier to change size of leading zeros
  • How to do transactions using MongoDB C driver with FoundationDB Document Layer?
  • Array of structs doesn't take input properly
  • Are assertions skipped when running in no debug mode?
  • free memory used for struct in C but fails (code from C Primer Plus 6th Edition)
  • Is the meaning of l-value different in c and c++?
  • How to convert 1D char to 2D int array and pass it int C?
  • Why does fputs() require a constant as first parameter and not fputc()?
  • how to pass string as a function parameter
  • Socket code fails when compiled with -O flag
  • How to exit safely from a loop while working on a growing input file?
  • the value of sizeof('0') is how much?
  • whats the reason for the xml2-config not found while compiling libxml2?
  • Can I use chars as integers in an if statement?
  • How can I check if a struct type has been defined before?
  • Longest portable unsigned integer type
  • what is array decay in c and when it happen?
  • malloc of a structure in C ( ported from C++ )
  • Superfluous (erroneous) message in the Windows message loop of child window when selecting a file
  • How to read stack trace kernelside in ebpf?
  • function of void type returning pointers
  • block statements, commas, and control expressions in C
  • Calculate the histogram with OpenMP
  • how to use pointer to write a struct to a piece of memory
  • prep string array for strlen
  • what is significance of bind to zero address
  • Does my system support monotonic clock?
  • Determining if a packet if type IPv4 or IPv6
  • printf statement in color
  • Where are "_Jv_RegisterClasses" and "clock_gettime" defined on 32 bit Linux?
  • For an Integer Array |a| and Integer |i| in C, a[i] gives the same result as i[a]
  • C Reading in integers from txt without fscanf
  • how does load command file in unix gets parameter?
  • Is it possible to use fopen to read a file with a relative path in C on OS X?
  • OpenGL ES 2.0: Object flattens as it rotates
  • Passing float as argument screws up value
  • inet_pton() gives "Segmentation fault"
  • tracing through bitwise & and ^ in C
  • How to prompt the user to enter a integer within a certain amount of numbers
  • Pointer taking input infinitely
  • Linked list only grabbing last input of File contents
  • How to determine if number represented by char array will overflow an int?
  • Creating arrays in C
  • Unhandled exception for character parsed from command line in Win32 API
  • Receiving strange number from fscanf - int conversion?
  • Need way to share file pointer between source files in C
  • Variables within gtk_label_set_markup
  • Why is this not evaluating properly? (Project Euler 9 - C)
  • Makefile complication error. Undefined reference C Programming
  • libc.h: No such file or directory when compiling nanomsg pipeline sample
  • C - pthreads appear to only be utilizing one core
  • statically linking libs. c compilation
  • Link and compile an assembly function
  • Linked list gives same results C
  • Error when when using a struct as function parameter?
  • Initializing a const variable with ntohl()
  • keyword/compiler option in C to promise not to overlap different pointers
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org