Pointers I

Un puntero es una variable que contiene la dirección de memoria de un dato o de otra variable que contiene el dato. Quiere esto decir, que el puntero apunta al espacio físico donde está el dato o la variable.

Su sintaxis de declaración sería:
tipo *NombrePuntero;

Donde tipo es el tipo de dato al que referenciará este puntero, es decir, que si se necesita guardar la dirección de memoria de un dato int, se necesita un puntero de tipo int.

int a=0; //Declaración de variable entera de tipo entero
int *puntero; //Declaración de variable puntero de tipo entero
puntero = &a; //Asignación de la dirección memoria de a

El operador *, nos permite acceder al valor de la dirección que almacena el puntero, en este caso nos permite acceder al valor que contiene a. De esta forma “a” y “*puntero” muestran el mismo dato, pero esto no quiere decir que sea lo mismo, uno es un entero el otro un puntero.

Operadores

Operador addresof (&): Este devuelve la dirección en memoria de una variable que le pasamos como parámetro. Funciona a priori como una función, cuyo retorno es una dirección de memoria.

Operador de Indirección (*): Ademas de que nos permite declarar un tipo de dato puntero, también nos permite ver el VALOR que está en la dirección a la que apunta el puntero.

No confundir con type * name, lo que sería una declaración de puntero, ni 2*2, lo que sería una operación aritmética, en este caso la multiplicación.

En C++ el símbolo de * está pluriempleado.  :mrgreen:

Javadocs

Javadoc es una utilidad de Oracle para la generación de documentación de APIs en formato HTML a partir de código fuente Java. Javadoc es el estándar de la industria para documentar clases de Java. La mayoría de los IDEs los generan automáticamente.


Javadoc también proporciona una API para crear doclets y taglets, que le permite analizar la estructura de una aplicación Java. Así es como JDiff puede generar informes de lo que ha cambiado entre dos versiones de una API.


Para generar APIs con Javadoc han de usarse etiquetas (tags) de HTML o ciertas palabras reservadas precedidas por el carácter “@”. Estas etiquetas se escriben al principio de cada clase, miembro o método, dependiendo de qué objeto se desee describir, mediante un comentario iniciado con “/**” y acabado con “*/”.


Netbeans ayuda en la generación de Javadocs de modo automático.


Las etiquetas en Javadocs son:

Tag Descripción
@author Nombre del desarrollador.
@deprecated Indica que el método o clase es antigua y que no se recomienda su uso porque posiblemente desaparecerá en versiones posteriores.
@param Definición de un parámetro de un método, es requerido para todos los parámetros del método.
@return Informa de lo que devuelve el método, no se puede usar en constructores o métodos “void”.
@see Asocia con otro método o clase.
@throws Excepción lanzada por el método
@version Versión del método o clase.



Un ejemplo de un Javadoc de un método:

/**
  * Inserta un título en la clase descripción.
  * Al ser el título obligatorio, si es nulo o vacío se lanzará
  * una excepción.
  *
  * @param titulo El nuevo título de la descripción.
  * @throws IllegalArgumentException Si titulo es null, está vacío o contiene sólo espacios.
  */
 public void setTitulo (String titulo) throws IllegalArgumentException
 {
   if (titulo == null || titulo.trim().equals(""))
   {
       throw new IllegalArgumentException("El título no puede ser nulo o vacío");
   }
   else
   {
       this.titulo = titulo;
   }
 }

ios App installation over the air with http/S

Getting “Cannot install applications because the certificate is not valid” error on iOS?

Cause:

With the launch of iOS 7.1, Apple requires the enterprise apps manifest file (.plist) to be served over HTTPS. Attempts to install through HTTP cause the above message.

A change was introduced to iOS as of iOS 7.1 that requires OTA application installation to take place over HTTPS (rather than HTTP), and no provision exists to allow the user to continue to accept the old behavior (i.e., to permit application installation over HTTP). It is my understanding that this was done as a security enhancement.

Solution:

In order to do application installations on iOS 7.1 from Application Center, you would need to configure your Application Center to use HTTPS rather than HTTP, using a certificate that will be accepted as valid by your iOS device – that is, either issued by a recognized public CA, or issued by a private CA that you have set up your mobile devices to accept.

Nearly five million jobs in European app sector by 2018 – EU report

The European Union’s (EU) app sector has gone from zero to digital superhero in less than five years and by 2018 it could employ 4.8 million people and contribute €63bn to the EU economy, according to a report presented in Brussels today.

Today the app economy employs a million developers, and 800,000 people in marketing and support posts. This could rise to 2.7 million developers over 2.1 million support staff by 2018.

EU buyers and advertisers spent €6.1bn on apps in 2013, 30pc of total global app spending, growing to €18.7bn in 2018.

Consumer spending combined with advertising and contract work could lead to €63bn annual revenue for the app sector within five years.

“In the face of increasing youth unemployment, these figures give me new hope,” said Neelie Kroes, vice-president of the European Commission.

“The app sector is one area of the digital economy where Europe can really lead. But we have to address concerns about connectivity and fragmentation – yet another reason to complete the telecom single market.”

Recursion – The basics

Recursion – The basics

 

COMPUT: a programming technique where a routine performs its task by delegating part of it to another instance of itself.

Introduction
For new computer science students, the concept of recursive programming is often difficult. Recursive thinking is difficult because it almost seems like circular reasoning. It’s also not an intuitive process; when we give instructions to other people, we rarely direct them recursively.

For those of you who are new to computer programming, here’s a simple definition of recursion: Recursion occurs when a function calls itself directly or indirectly.

A classic example of recursion
The classic example of recursive programming involves computing factorials. In mathematics, the factorial of a nonnegative integer, n (denoted n!) is the product of all positive integers less than or equal to n. For example, 5! is the same as 5*4*3*2*1, and 3! is 3*2*1.

An interesting property of a factorial is that the factorial of a number is equal to the starting number multiplied by the factorial of the number immediately below it. For example, 5! is the same as 5 * 4! You could almost write the factorial function as:

int factorial(int n)
{
   return n * factorial(n - 1);
}

Listing 1. First cut factorial function

However, there is a small problem with this; it will run forever because there is no place where it stops calling itself. It therefore needs a condition to tell it to stop. Since a factorial is for positive numbers only it makes sense to stop the recursion when the input is 1 and return 1 as the result. The modified code will look like this:

int factorial(int n)
{
   if(n == 1)
   {
      return 1;
   }
   else
   {
      return n * factorial(n - 1);
   }
}

Listing 2. better factorial function

As you can see, as long as the initial value is above zero, this function will terminate. Note that more work will need to be done to guard again invalid initial values.

The point at with the recursion is stopped is called the base case. A base case is the bottom point of a recursive program where the operation is so trivial as to be able to return an answer directly. In the case of a factorial 1! = 1. All recursive programs must have at least one base case and must guarantee that they will hit one eventually; otherwise the program would run forever or until the program ran out of memory or stack space.

recursion

Basic steps of recursive programs
All recursive programs follows the same basic sequence of steps:
1: Initialize the algorithm. Recursive programs often need a seed value to start with.
2: Check to see whether the current value(s) being processed match the base case. If so, process and return the value.
3: Redefine the answer in terms of a smaller or simpler sub-problem or sub-problems.
4: Run the algorithm on the sub-problem.
5: Combine the results in the formulation of the answer.
6: Return the results.

 

Advantages and drawbacks of recursion

Main advantage of recursion is programming simplicity. When using recursion, programmer can forget for a while of the whole problem and concentrate on the solution of a current case. Then, returning back to the whole problem, base cases (it’s possible to have more than one base case) and entry point for recursion are developed.

On the other hand, recursion has a serious disadvantage of using large amount of memory. Moreover, for most programming languages, recursion use stack to store states of all currently active recursive calls. The size of a stack may be quite large, but limited. Therefore too deep recursion can result in Stack Overflow. To resolve this problem recursion can be simulated, using loop and stack data structure.

Method Vs Function

Method Vs Function

A function is a piece of code that is called by name. It can be passed data to operate on (ie. the parameters) and can optionally return data (the return value).

All data that is passed to a function is explicitly passed.

A method is a piece of code that is called by name that is associated with an object. In most respects it is identical to a function except for two key differences.

1. It is implicitly passed the object for which it was called

2. It is able to operate on data that is contained within the class (remembering that an object is an instance of a class – the class is the definition, the object is an instance of that data)
(this is a simplified explanation, ignoring issues of scope etc.)

Summarizing…

A method is on an object.A function is independent of an object.

For Java, there are only methods.For C, there are only functions.

For C++ it would depend on whether or not you’re in a class.

Global and Local Variables

A scope is a region of the program and broadly speaking there are three places, where variables can be declared:

  • Inside a function or a block which is called local variables,
  • In the definition of function parameters which is called formal parameters.
  • Outside of all functions which is called global variables.

We will learn what is a function and it’s parameter in subsequent chapters. Here let us explain what are local and global variables.

#include <iostream>
using namespace std;

int main ()
{
  // Local variable declaration:
  int a, b;
  int c;

  // actual initialization
  a = 10;
  b = 20;
  c = a + b;

  cout << c;

  return 0;
}

Global Variables:

Global variables are defined outside of all the functions, usually on top of the program. The global variables will hold their value throughout the life-time of your program.

A global variable can be accessed by any function. That is, a global variable is available for use throughout your entire program after its declaration. Following is the example using global and local variables:

#include <iostream>
using namespace std;

// Global variable declaration:
int g;

int main ()
{
  // Local variable declaration:
  int a, b;

  // actual initialization
  a = 10;
  b = 20;
  g = a + b;

  cout << g;

  return 0;
}

A program can have same name for local and global variables but value of local variable inside a function will take preference. For example:

#include <iostream>
using namespace std;

// Global variable declaration:
int g = 20;

int main ()
{
  // Local variable declaration:
  int g = 10;

  cout << g;

  return 0;
}

When the above code is compiled and executed, it produces the following result:

10

Initializing Local and Global Variables:

When a local variable is defined, it is not initialized by the system, you must initialize it yourself. Global variables are initialized automatically by the system when you define them as follows:

Data Type Initializer
int 0
char ‘\0’
float 0
double 0
pointer NULL

It is a good programming practice to initialize variables properly, otherwise sometimes program would produce unexpected result.