Today we are going to be looking at some basic syntax and semantics between the programming languages C, C++, and Java. I’ll run and rewrite the same code as well as explain the results.

Let’s start by creating a function that includes the following sequence of statements:

x = 21;
int x;
x = 42;

Programmed in C:

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
function() {
x = 21;
int x;
x = 42;
printf("%d", x);
}
int main() {
function();
return 0;
}

A compiler error is thrown here, caused by the undefined identifier ‘x’. This is because a…

Daniel Navarro

Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store