^^Linguaggio C  C++.

 

Le keywords del C sono poche, 32

auto  break  case  char  const  continue  default  do  double  else  enum  extern  float  for  goto  if  int  long  register  return  short  signed  sizeof  static  struct  switch  typedef  union  unsigned  void  volatile  while 

 

int     numero intero

long    da -2.147.483.648  a  2.147.483.647   4 byte

float   da -3.4028235⋅10+38  a  3.4028235⋅10+38.

double  raddpppia i bit del float
 

char   un_carattere = ‘a’;   // virgolette singole

 

Il linguaggio C è "senza I/O"

I/O e' affidato a funzioni di libreria.

In pratica sono universalmente accettate le funzioni di I/O scritte dai creatori del linguaggio, che quindi sono diventate uno standard de facto.

Hello World!

C++ inherits most of C's syntax. The following is Bjarne Stroustrup's version of the Hello world program that uses the C++ Standard Library stream facility to write a message to standard output:

 

#include <iostream>

int main()
{
    std::cout << "Hello, world!\n";
}

 

C++ e' un linguaggio a oggetti, e' la differenza principale tra C e C++

 

 

Per imparare a programmare in C/C++

utilizzare un ambiente di programmazione on-line: www.ideone.com

1° programma: "Hello world"

#include <stdio.h>
 

int main(void) {
  printf("Hello world");
return 0;
}

#include <stdio.h>
 

main() {
  printf("Hello world");
}

 

#include <stdio.h>

include nel testo del programma il file stdio.h

stdio.h   contiene ....   h = header

Codice di risposta

Un programma eseguibile deve obbligatoriamente restituire un numero, codice di risposta.

 

\n per andare a capo

 

Array. 1D, 2D, multidimensional

1-dim, 2-dim    1D, 2D

dimensions    indexes    subscripts

https://www.tutorialspoint.com/arduino/arduino_multi_dimensional_arrays.htm

no checking bounds

the C++ compiler does no checking to see if array access is within legal bounds of the array size that you have declared.

2D array

  1. Arrays with two dimensions often represent
  2. By convention, the first identifies the element’s row and the second identifies the element’s column.

Read array

int Matrix[Y][X];
for (int i =0; i < Y; i++) {
  for (int j =0; j < X; j++) {
    Matrix[i][j] = some data;
  }
}

Init array2D

int Matrix[][X] = {
{1,2,3,...,X},   // virgola
{3,4,5,...,X},
{1,9,2,...,X},
{9,8,7,...,X}    // no virgola
};

 

Come copiare o riferire in un array 2D gli array riga

// addr=addr2;        invalid array assignment
//addr = dev_id[i];   invalid array assignment
 

stringa := array di caratteri terminato da null

#include <iostream>
int main() {
  char parole[] = "mela pera miele";  // stringa := array di caratteri
   printf("parole a caso: %s", parole);
return 0;
}

in memoria la stringa viene terminata dal byte null, dal compilatore, non va scritto,

#include

Syntax

#include <file.h> angle brackets, the libraries paths will be searched for the file.

.h estension, is a header file library

#include "file.h" double quotes syntax, the folder of the file using the #include directive will be searched for the specified file, then the libraries paths if it was not found in the local path. Use this syntax for header files in the sketch’s folder.

#define

Since macros do literal source-level replacement, you will tend to get side-effects if you pass an argument to one, like "a++".

What does :: in C++ code?
What does :: mean in C++?

:: Scope Resolution Operator    it makes it clear to which namespace or class a symbol belongs.  wp | stackoverflow

es: AirlineTicket::AirlineTicket()

used to separate the class AirlineTicket from in this case the constructor AirlineTicket(), forming the qualified name AirlineTicket::AirlineTicket()

Type

stackoverflow/stdint.h-VS-inttypes.h

wp/C_data_types#inttypes.h

Links

  1. Kernighan, Ritchie, Thompson.
  2. Programming languages
  3. Arduino.