Hubbry Logo
logo
C syntax
Community hub

C syntax

logo
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Contribute something to knowledge base
Hub AI

C syntax AI simulator

(@C syntax_simulator)

C syntax

C syntax is the form that text must have in order to be C programming language code. The language syntax rules are designed to allow for code that is terse, has a close relationship with the resulting object code, and yet provides relatively high-level data abstraction. C was the first widely successful high-level language for portable operating-system development. C syntax makes use of the maximal munch principle. As a free-form language, C code can be formatted different ways without affecting its syntactic nature. C syntax influenced the syntax of succeeding languages, including C++, Java, and C#.

C code consists of preprocessor directives, and core-language types, variables and functions; organized as one or more source files. Building the code typically involves preprocessing and then compiling each source file into an object file. Then, the object files are linked to create an executable image.

Variables and functions can be declared separately from their definition. A declaration identifies the name of a user-defined element and some if not all of the information about how the element can be used at run-time. A definition is a complete description of an element that includes the declaration aspect as well as additional information that completes the element. For example, a function declaration indicates the name and optionally the type and number of arguments that it accepts. A function definition includes the same information (argument information is not optional), plus code that implements the function logic.

For a hosted environment, a program starts at an entry point function named main. The function is passed two arguments although an implementation of the function can ignore them. The function must be declared per one of the following prototypes (parameter names shown are typical but can be anything):

The first two definitions are equivalent; meaning that the function does not use the two arguments. The second two are also equivalent; allowing the function to access the two arguments.

The return value, typed as int, serves as a status indicator to the host environment. Defined in <stdlib.h>, the standard library provides macros for standard status values: EXIT_SUCCESS and EXIT_FAILURE. Regardless, a program can indicate status using any values. For example, the kill command returns the numerical value of the signal plus 128.

A minimal program consists of a parameterless, empty main function, like:

Unlike other functions, the language requires that a program act as if it returns 0 even if it does not end with a return statement.

See all
set of rules governing writing of software in the language
User Avatar
No comments yet.