Format of C

The Format of C 

1
2
3
4
5
6
7
#include <stdio.h> 				/* comment */ 
int main(void)
{
  printf("Hello\n");  	
  printf("Welcome to the Course !\n");    	
  return 0;
}

  

  • Statements are terminated with semicolons
  • Indentation is ignored by the compiler like Comment
  • C is case sensitive - all keywords and Standard Library functions are lowercase
  • Strings are placed in double quotes
  • Newlines are handled via \n
  • Programs are capable of flagging success or error, those forgetting to do so have one or other chosen randomly! 

 Another Example

1
2
3
4
5
6
7
8
9
#include<stdio.h>
int main(void)
{
  int a,b;  	
  printf("Enter two Numbers :");  	
  scanf("%i %i", &a,&b);  	
  printf("%i - %i = %i\n",a,b,a-b);  	
  return 0;
}

 here int keyword is used to create integer variables. here two variables a and b are created.

Variables

  • Variables must be declared before use immediately after begin “{“.
  • valid characters are letters, digits and ”_”.
  • First character cannot be a digit.
  • 31 characters recognised for local variables (more can be used, but are ignored).
  • Some implementations recognise only 6 characters in global variables (and function names)!.
  • Upper and lower case letters are distinct.

printf and scanf

  • printf writes integer values to screen when %i is used.
  • scanf reads integer values from the keyboard when %i is used.
  • “&“ VERY important with scanf (required to change the parameter, this will be investigated later) - absence will make program very ill.
  • “&“ not necessary with printf because current value of parameter is used.

Integer Types in C

  • C supports different kinds of integers
  • maxima and minima defined in “limits.h”

type                             format         bytes  
char                             %c                   1         
signed char                  %c                   1         
unsigned char             %c                   1         
short [int]                    %hi                  2         
unsigned short             %hu                 2         
int                                %i                    2         
unsigned int                %u                   2or4
long [int]                     %li                   4
unsigned long              %lu                  4

Integer Example

1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>
#include <limits .h>
int main(void)
{
  unsigned long big = ULONG_MAX;   
  Printf(”minimum int = %i,  INT_MIN);   
  printf(”maximum int = %i\n, INT_MAX);   
  printf(”maximum unsigned = %u\n, UINT_MAX);  
  printf(”maximum long mnt = %li\n, LONG_MAX);  
  printf(”maximum unsigned 1ong = %lu\n", big);
  return 0; 
}

Output

minimum int = -32768, maximum int = 32767

maximum unsigned = 65535 

maximum long int = 2147483647

maximum unsigned long = 4294967295

Integer With Different Bases

It is possible to work in octal (base 8) and hexadecimal (base 16)

1
2
3
4
5
6
7
8
#include <stdio.h>
int main(void)
{   
	int dec = 20, oct = 020, hex = 0x20;
    printf("dec=%d, oct=%d, hex=%d\n", dec, oct, hex);  
    printf("dec=%d, oct=%o, hexe%x\n", dec, oct, hex);
    return 0; 
}

 Output

dec=20, oct=16. hex=32
dec=20, oct=20, hex=20

Named Constants

Named constants may be created using const 

1
2
3
4
5
6
7
8
9
#include <stdio.h> 
int main(void) 
{   
	const  long double pi = 3.141592653590L;
  	const int days_in_week = 7;   
  	const sunday = 0;   
  	days_in_week = 5;   
  	return 0; 
} 

Preprocessor Constants

Named constants may also be created using the Preprocessor
Needs to be in “search and replace” mode
Historically these constants consist of capital letters 

1
2
3
4
5
6
#include <stdio.h>
#define	PI            3.141592653590b 
#define	DAYS_IN_WEEK   	     7 
#define	SUNDAY               0 
int day = SUNDAY;
long flag = USE_API;

 

 

Research and Development

With a focus on R&D, Micromagine embedded software engineers go far and wide exploring the breadth of capabilities and fields of application for the next generation of industry hallmarks, identifying the potential pockets of growth for our customers.
Some of the latest examples of our R&D include studying and testing Android OS porting to custom hardware platforms and trying new dimension technologies such as motion controller in game development.

Embedded System Expertise

  • Deep experience across multiple embedded platforms (ARM Cortex M series, ARM64/aarch64, Intel x86-64)

  • Custom device driver design and implementation (Linux or microcontroller or otherwise)

  • Video- and audio-rate (or higher), low-latency DSP algorithms

  • Multi-threaded applications and data processing

  • Rapid prototyping

Quality Assurance

Quality Assurance of embedded systems is also available as a separate service for our clients. We provide testing and debugging for a range of embedded solutions.
To craft efficient, resilient, and infallible software, we’ve established two focused QA Labs: Firmware & Embedded QA Lab, and Mobile QA Lab, which are applicable during unit, integration, system, and acceptance testing.

 

Powered By by Micromagine Web Solutions