Showing posts with label c language. Show all posts
Showing posts with label c language. Show all posts

Tuesday, July 16, 2013

Learn C# programming language : Lesson 001 Introduction

Introduction to the C# language and .Net Framework

C# is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the .net framework. You can use C# to crate traditional windows client applications, XML web services , distributed components, client-server applications, database applications, and integrated debugger, and many other tools to make it easier to develop applications based on version 4.0 of the C#  language and version 4.0 of the .NET framework.

C# language

C# syntax is highly expressive , yet it is also simple and easy to learn. The curly- brace syntax of C# will be instantly recognizable to anyone familiar with C, C++ or java. Developers who know any of these languages are typical bale to begin t work productively in C# within a very short time C# syntax simplifies many of the complexities of C++ and provides powerful features such an null-able value types, enumerations, delegates lamda expressions and direct memory access, which are not found in java. C# supports generic methods and types which provide increased type safety and performance and iterators, which enables implementer of collection classes to define custom iteration behavior that are simple to use by client code. Language Integrated Query (LINQ) expressions make the strongly typed query a first class language construct.

An Object Oriented language C# supports the concepts of encapsulation, inheritance and polymorphic, All variables and methods, including the Main method , the application's entry point , are encapsulated within class definitions, A class may inherit directly from one parent class, but it may implement any number of interface methods that override virtual methods in a parent class require the override keyword as a way to avoid accidental redefinition . 

There are no header files, and no requirement that methods and types be declared in a particular order. A C# file may define any number of classes, structs , interfaces , and events.

C#.net having code Best Security Because
  1. it is case sensitive
  2. Every statement ends with terminator i.e. semicolon(;)
  3. Every Block quoted by curly Braces ({})
  4. It is purely Maintain type Conversion.

Sunday, June 16, 2013

Programming in C - 2. Input/Output Operations

C language does not have any built-in Input- Output (I/O) statements as a part of its syntax.
All the Input/Output operations are carried out through functions calls such as printf() and scanf()


scanf() 



  • General purpose console input function. Also used to input a data line containing mixed mode data.
  • syntax : scanf ("format specifier", variable_list); // end with semi-colon and case-sensitive.
  • 'format specifier' specifies the field format in which the data has to be entered.
  • 'variable list' specifies the address of the location where the data is stored.
  • use '%' before format sepecifier and '&' before a variable name
Format Specifier
  • It contains specifications for the interpretation of input data.
  • '%' conversion character.
  • list of format specifier
    • %c To read a single character
    • %d To read a decimal integer
    • %e To read a floating point value
    • %f  To read a floating point number
    • %g To read a floating point value
    • %o to read an octal value
    • %x To read an Hexadecimal value
    • %s To read a String
    • %u To read an unsigned integer
  • For reading a string 
    • scanf("%s", &st); // st contains the string value
  • For reading two values
    • scanf("%d,%d",&a,&b);\
  • Features :
    • format specification and variable list must correctly match the same order
    • The format specifier must be separated by space or comma and vairable list by comma
    • use of invalid match between format specifier and variable list will make the scanf() to terminate the reading of data

printf()

  • syntax : printf ( " format specifier ", variable list);
  • never takes the print to the new line so we use '\n' for a new line
  • eg : printf(" no of chocolates = %d \n no of sweets = %d",&a,&b); // ouput : no of chocolates = 12 [next line ] no of sweets = 13 // where a = 12 and b =13
  • list of escape sequences like \n 
    • \b     back space
    • \f      Form feed
    • \n     New line
    • \r     Carriage return
    • \t     Horizontal tab
    • \"     Double quote mark
    • \'     single quote mark
    • \0    null
    • \\     Back slash
    • \v    Vertical tab
    • \a    Alert ( rings a bell)
    • \o    Octal constant
    • \x     Hexadecimal constant

Sample Program :


First you need :
Compiler :
online compiler : codepad.org
offline compiler : http://edn.embarcadero.com/article/20633 (borlan c++ compiler)
                           http://www.digitalmars.com/ (digital mars c compiler)

01 #include <stdio.h> // imports the header file stdio.h which contains the definitions of scanf() and printf()
                                     functions.
02 void main() // execution of the program begins in the main() function
03 {
04       printf(" Hello world ");
05 } // main() ends here

output : Hello world 



Next Article : Programming in C - 3. Control Statements and Arrays

Saturday, June 15, 2013

Programming in C - 1. Fundamentals

C  is a general-purpose programming language initially developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs. ( Source : Wiki )
Middle Level Language
Portable
Structured language.

The C grammer :

  1. Charecter set : used to form words, numbers and expressions , in any programming language. It includes Letters, Digits, Special charecters
  2. Token : Fundamental units of C language. It include  Identifiers, Keywords, Literals, Operators, white Spaces.
    • Identifiers : Name of variable , a constant or a function.
    • keywords : C has almost 32 keywords. They are reserved words which cannot be used for naming variables.
    • Constants : It is the Value of Quantitiy.
  3. Data Types : It is used to determing the kind of data the variable can store. It has four basic data types int, float, char and void.
    • Integer : these are numbers without decimal part that may or may not be prefixed with a negative sign.
    • Float : These are numbers with decimal part in it.
    • Void : It has no value. It can be used to declare a funtion that retuns no values, it creates generic pointers.
  4. Operators : An Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulation.
    • assignment : =, ==
    • auto increment / decrement : ++, --
    • ternary : (x>y)?x:y
    • logical : && (AND), || (OR), ! (NOT)
    • relational : <, >, <=,>=
    • cast : (type_name) expression
    • arithmetic : +, -, %
    • bitwise : &, |, -(compliment)
    • special

Next : Programming in C - 2. Input and output Operations