samedi 27 mai 2017

C++ 11 - Structure initialisation - Braced init list

/**************** dummy.h *****************/
#ifndef DUMMY_H /* Header guard */
#define DUMMY_H

#include <stdio.h>
#include <stdlib.h>
using namespace std;

struct X
{
  int a;
  double b;
  int *ptr;
};
#define TWOBYTES 2

#endif


/************* dummy.cpp ********************/
#include "dummy.h"

int main(int argc, char *argv[])
{
  X x {1, 2.3, (int *)malloc(TWOBYTES)};
  auto ptr = &x;
  printf("value of %d\n", ptr->a);
  return 0;
}


$ g++ -std=c++11 dummy.cpp $

Question:

Is ptr->a pointing to location with value 2?

Aucun commentaire:

Enregistrer un commentaire