I’ve been doing some exercises from a book and I’m wondering if you could tell me if they are correct. It’s not a homework, I’m just practicing. I’ve commented what should I have to do and my actual code
#include <iostream>
#include <string>
using namespace std;
//int main(){}
// 1
char *ptc; //pointer to char
int Array[10]; //array of 10 ints
int (&arrayRef)[10] = Array; //ref to Array
string *pts; //pointer to a array of strings
char** pptc; //pointer to pointer to char
const int const_int =0; //constant integer
const int* cpti; //constant pointer to a integer
int const* ptci; //pointer to constant integer
// 3
typedef unsigned char u_char; //u_char = 2;
typedef const unsigned char c_u_char; //c_u_char = 2;
typedef int* pti; //pti = &Array[0];
typedef char** tppc; //ttpc = ptc; ?
typedef char *ptaoc; //pointer to array of char
typedef int* pta; //array of 7 pointers to int ?
pta myPTA = (int *)calloc(7, sizeof(int));
typedef int** pta2; //pointer to an array of 7 pointers to int ?
pta2 mypta2 = &myPTA;
/* ??? */ //array of 8 arrays of 7 pointers to int
// 4
void swap1(int *p, int *q) //this should swap the values of p & q but the last line isn't working q = &aux??
{
int aux; //int a = 5, b = 8;
//swap1(&a, &b);
aux = *p;
*p = *q; //it returns 8 and 8
q = &aux;
}
int main()
{
}
EDIT:
the problem is :how do i declare array of 8 arrays of 7 pointers to int
is this correct?
typedef char** tppc; //ttpc = ptc; ?
typedef char *ptaoc; //pointer to array of char
typedef int* pta; //array of 7 pointers to int ?
pta myPTA = (int *)calloc(7, sizeof(int));
typedef int** pta2; //pointer to an array of 7 pointers to int ?
pta2 mypta2 = &myPTA;
and why isn’t function swap1 working?
ad 1)
To declare a declare array of 8 arrays of 7 pointers to int you have to type the following:
ad 2)
Your swap function isn’t working because you are setting the pointer to a function local variable.
A small change, and everything should work well: