Sponsored Content
Top Forums Programming C pointer/array duality confusion Post 302427722 by gorga on Monday 7th of June 2010 03:51:37 PM
Old 06-07-2010
Thanx for your reply,

"you're trying to initialize a struct, from a pointer."

I thought with the typedef...

Code:
typedef section_t* region_t[SECTION_LENGTH];

This would mean that the following statement would be assigning a ptr to a ptr...

Code:
region_t region = ctn.regions[nth];

Because a region_t is a ptr type...or in other words, an array of section_t* ptrs. Hence my confusion, I thought in C an array and a ptr were essentially the same things, so this would work.

Anyway I got it to work by changing the assignment to the following...
Code:
section_t** region = ctn.regions[nth];

I realised that "ctn.regions[nth]" is basically an array without the subscript, which means it's a ptr. And what it points to is a ptr to a "section_t"... voila a ptr to a ptr.

And I can access the section_t* by using the subscript, i.e...

Code:
  region[i]->section_t_data_member = x;

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

confusion (file pointer and file descripter)

Hi everybody, i am newbie to unix and confused with file pointers and file descripters. could anyone help me to clear my doubts .. when we call unix system calls to create a file then we are dealing wih file descripters i think file descripters are also normals file as stored inhard disks... (1 Reply)
Discussion started by: johnray31
1 Replies

2. UNIX for Dummies Questions & Answers

Storing pointer array in C

All .. I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced code: int cnt1; char *t_array; char *f_array; for(cnt1=0; cnt1<1000; cnt1++) { t_array =... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

3. Programming

pass a pointer-to-pointer, or return a pointer?

If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it: (1) one is to pass a pointer-to-pointer parameter, like: int my_malloc(int size, char **pmem) { *pmem=(char *)malloc(size); if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies

4. Programming

help with char pointer array in C

i have an array like #define NUM 8 .... new_socket_fd = accept(socket_fd, (struct sockaddr *) &cli_addr, &client_length); char *items = {"one", "two", "three", "four", "five", "six", "seven", "eight"}; char *item_name_length = {"3", "3", "5", "4", "4", "3", "5", "5"}; ... (1 Reply)
Discussion started by: omega666
1 Replies

5. Programming

structure pointer array as function parameters

if i create an array of pointers to a structure "struct node" as: struct node *r; and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as: r=multiplty(.......) /*some parameters*/ is... (2 Replies)
Discussion started by: mscoder
2 Replies

6. Programming

Unclear pointer and array

Hello, The purpose of the program is to print a sub string from the prompt inputs. I do not understand why char pointer does not work but char array will for line 40 and Line 41. ./a.out thisisatest 0 8 substring = "thisisat"And my code is: #include <stdio.h> #include <stdlib.h> #include... (29 Replies)
Discussion started by: yifangt
29 Replies

7. Programming

Pointer confusion

Here are two programs that pass a pointer to a variable but behave differently. Shouldnt the i in second program be 0 after the function call? #include<stdio.h> void changeI(int *i) { *i = 10; } int main(void) { int i=5; printf("%d before\n", i); changeI(&i); printf("%d... (1 Reply)
Discussion started by: dragonpoint
1 Replies

8. UNIX for Dummies Questions & Answers

File System and Storage Array Confusion

Hi Friends, I have a host(Suse Linux 10.4) which has 2 luns presented from 2 different arrays HP eva and xp. we are planning to migrate hp eva to 3par. When i look for physical volume i see /dev/dm-4, /dev/dm-5, /dev/dm-7and when i look for multipath -ll i see dm-8,dm-9,dm-7. So i can't confirm... (6 Replies)
Discussion started by: munna529
6 Replies

9. Programming

Character pointer to Character array

how to copy content of character pointer to character array in c programming.. char *num; char name=num; (1 Reply)
Discussion started by: zinat
1 Replies

10. Programming

Pointer for 2D array seems to be 3D in C

I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines? I have talked to one of the curators of the forum, but I am still not quite clear. Here... (1 Reply)
Discussion started by: yifangt
1 Replies
std::array< _Tp, _Nm >(3cxx)											      std::array< _Tp, _Nm >(3cxx)

NAME
std::array< _Tp, _Nm > - SYNOPSIS
Public Types typedef const value_type * const_iterator typedef const _Tp * const_pointer typedef const value_type & const_reference typedef std::reverse_iterator < const_iterator > const_reverse_iterator" typedef std::ptrdiff_t difference_type typedef value_type * iterator typedef _Tp * pointer typedef value_type & reference typedef std::reverse_iterator < iterator > reverse_iterator" typedef std::size_t size_type typedef _Tp value_type Public Member Functions reference at (size_type __n) const_reference at (size_type __n) const reference back () const_reference back () const iterator begin () const_iterator begin () const const_iterator cbegin () const const_iterator cend () const const_reverse_iterator crbegin () const const_reverse_iterator crend () const _Tp * data () const _Tp * data () const constexpr bool empty () const iterator end () const_iterator end () const void fill (const value_type &__u) reference front () const_reference front () const constexpr size_type max_size () const reference operator[] (size_type __n) const_reference operator[] (size_type __n) const reverse_iterator rbegin () const_reverse_iterator rbegin () const reverse_iterator rend () const_reverse_iterator rend () const constexpr size_type size () const void swap (array &__other) Public Attributes value_type _M_instance [_Nm?_Nm:1] Detailed Description template<typename _Tp, std::size_t _Nm>struct std::array< _Tp, _Nm > A standard container for storing a fixed size sequence of elements. Meets the requirements of a container, a reversible container, and a sequence. Sets support random access iterators. Parameters: Tp Type of element. Required to be a complete type. N Number of elements. Definition at line 60 of file array. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Nov 27 2012 std::array< _Tp, _Nm >(3cxx)
All times are GMT -4. The time now is 03:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy