tag:blogger.com,1999:blog-73897753169106366922024-02-08T10:23:10.442-08:00c difference betweenhere we are going to discuss various problems related to programming language c..jameshttp://www.blogger.com/profile/06329212436216944855noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-7389775316910636692.post-19408983368892618822012-08-30T03:47:00.003-07:002012-08-30T07:09:50.826-07:00Data types and names in c<div dir="ltr" style="text-align: left;" trbidi="on">
<b>The char data type: </b>An object of char data type represents a single character e.g a, b, d, A, F, D, 5,9 &,%,( etc.<br />
computer can only store numeric code, therefore characters such as A, a, B, b and so on all have a unique numeric code that is used by computers to represent the characters. For many computers, the ASCII codes are the standard code that is used by the computer to represent a character set.<br />
<br />
Character Variable: A variable that can represent different characters is called the character variable.<br />
e.g char sann;<br />
or char sann, s1, s2, stdnt; (you can define more than one characters in single line as shown here).<br />
<br />
To print a character we use character format specifier %c, which indicates to printf() function that the argument to be printed is a character.<br />
<br />
#include<stdio.h><br />
#include<conio.h><br />
void main()<br />
{<br />
char c1='a';<br />
char c2='5';<br />
printf("output: %c",c1);<br />
printf("output: %c",c2 );<br />
getch();<br />
}<br />
<br />
The int data type: The int keyword is used to specify the type of a variable as an integer. Integer numbers are also called the whole numbers.<br />
<br />
Declaring integer variables:<br />
int variablename;(basic declaration format).<br />
or int variablename1, variablename2, variablename3;<br />
<br />
int type:<br />
<br />
type size(byte) minimum value maximum value format specifer<br />
<br />
short int 2 -2^15 2^15-1 %hd<br />
int 2 -2^15 2^15-1 %d<br />
long int 4 -2^31 2^31-1 %ld<br />
long long int 8 -2^63 2^63-1 %lld<br />
<br />
Real numbers: The real type holds the values that consists of an integral part and fractional part such as 56.908. there are three different size of real types.<br />
(i) float (4 byes, %f, precision 6 digits) (ii) double (10 bytes, %f, precision 10 digits) (iii) long double (10 bytes, %Lf, precision 10 digits).<br />
<br />
variable declaration:<br />
float price;<br />
long double radius;<br />
double a;<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
jameshttp://www.blogger.com/profile/06329212436216944855noreply@blogger.com0tag:blogger.com,1999:blog-7389775316910636692.post-84507484468979203622012-08-24T21:18:00.001-07:002012-08-30T07:10:05.672-07:00the basics of c program<div dir="ltr" style="text-align: left;" trbidi="on">
As a building is made of bricks, a c program is made of basic elements such as expressions, statements, statement blocks, constants, and variables.<br />
<br />
<b>constants and variables: </b>A constant is a value that never changes while a variable can be used to present different values.<br />
ex. i=1, symbol '1' represents the constants and symbol 'i' represents the variable.<br />
<br />
<b>Expressions: </b>An expression is combination of constants, variables and operators that are used to denote the computations.<br />
<br />
for ex: (4+8)*6-i+7.<br />
<br />
<b>C-Arithmetic operator: </b><br />
<b>symbol meaning</b><br />
+ addition<br />
- subtraction<br />
* mmultiplication<br />
/ division<br />
% remainder <br />
<br />
<b>Statements: </b>A statement is a complete instruction, ending with a semicolon.<br />
e.g i=8;<br />
<br />
<b>Statement Blocks: </b>A group of statements can form a statement block that starts with an opening brace ({) and ends with a closing brace (}).<br />
e.g {<br />
s4=9-7;<br />
s3=s4+i;<br />
.<br />
.<br />
.<br />
}</div>
jameshttp://www.blogger.com/profile/06329212436216944855noreply@blogger.com0tag:blogger.com,1999:blog-7389775316910636692.post-60738234267398092162012-08-07T21:40:00.000-07:002012-08-30T07:10:05.664-07:00what is c programming language<div dir="ltr" style="text-align: left;" trbidi="on">
C is a programming language. The C language was first developed in 1972 by Dennis Ritchie at AT & T (American Telephone and Telegraph company) Bell labs.<br />
C is a high level programming language because it is closer to human language. While the lowest languages are machine language that computer understand directly.<br />
Example: The human language: "if line is not busy connect to the internet".<br />
High level language: if(line != busy) connect( internet).<br />
The machine language: 1001010100101111000011111010101010<br />
<br /></div>
jameshttp://www.blogger.com/profile/06329212436216944855noreply@blogger.com0tag:blogger.com,1999:blog-7389775316910636692.post-1684349942482899292012-07-27T23:51:00.001-07:002012-08-30T07:10:05.658-07:00Precedence and associativity in c<div dir="ltr" style="text-align: left;" trbidi="on">
Precedence: Precedence is used to determine the order in which different operators in complex expression are evaluated.<br />
<br />
Assiciativity: Associativity is used to determine the order in which operators with the same precedence are evaluated in a complex expression. It can be a left to right or right to left depends on the expression.<br />
<br />
Left to right associativity: 3*8/4%4*5<br />
Right to left associativity: Several operators have right to left associativity. for example when more than one assignment operator occur in an expression e.g a+=b*=c-=5 evaluated as (a+=(b*=(c-=5))).<br />
<br />
<br /></div>
jameshttp://www.blogger.com/profile/06329212436216944855noreply@blogger.com4tag:blogger.com,1999:blog-7389775316910636692.post-15882224310899596582012-07-27T23:41:00.000-07:002012-08-30T07:10:05.655-07:00difference between signed int and unsigned int (signed int vs unsigned int)<div dir="ltr" style="text-align: left;" trbidi="on">
Signed integer can store positive value as well as negative value while unsigned integer can store only positive value.<br />
<div>
For signed integer the range is -32768 to 32767 while for unsigned integer the range is: 0 to 65535.</div>
</div>
jameshttp://www.blogger.com/profile/06329212436216944855noreply@blogger.com0tag:blogger.com,1999:blog-7389775316910636692.post-66910031049515527382012-07-27T23:40:00.001-07:002012-08-30T07:10:05.666-07:00Expressions in c<div dir="ltr" style="text-align: left;" trbidi="on">
An expression is a sequence of operands and operators that reduces to a single value. An expression can be simple or complex. A simple expression contains only one operator e.g 2+5; A complex expression contains more than one operator e.g 2+5*3-9.<br />
<br />
Expression can be categorized into 6 parts.<br />
<br />
<b>Primary expressions</b>: A primary expression consists of only one operand with no operator. In c, the operand in the primary expression can be a name, a constant, or a parenthesized expression.<br />
<br />
names: a, b12, price, calc, etc....<br />
constants: 6,123.98, 'a'.<br />
<br />
<span style="background-color: white;">Parenthetical expression: (2+4*6-4).</span><br />
<br />
<b>Postfix expression</b>: The postfix expression consists of one operand followed by one operator.<br />
example postfix increment/ decrement e.g a++, a--;<br />
<br />
<b>Prefix expression: </b>In prefix expressions, the operator comes before the operand. example: prefix increment/decrement e.g ++a, --a;<br />
<br />
<br />
<b>Unary Expressions:</b> A unary expression, like a prefix expression consists of one operator and one operand.. Also like the prefix expression, the operator comes before operand. but the difference between unary and prefix expression is that prefix expression needs a variable as an operand, while unary expression can have an expression or a variable as the operand. ex- sizeof(int). +a,-a, float(x).<br />
<br />
<b>Binary Expressions:</b> Binary expressions are formed by an operand operator operand combination.<br />
example: 10*5, (2+38*i)*(1+3+i).<br />
<br />
<b>Assignement expression</b>: ex- a=5; b=90;<br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;"> </span></div>
jameshttp://www.blogger.com/profile/06329212436216944855noreply@blogger.com0tag:blogger.com,1999:blog-7389775316910636692.post-87233704099950499742012-07-21T02:19:00.000-07:002012-08-30T07:10:05.675-07:00difference between short int and int (int vs short int) ?<div dir="ltr" style="text-align: left;" trbidi="on">
Actually the size of int is fully dependent on machine and compiler. But c requires to maintains the following relationship: sizeof(short int)<=sizeof(int)<=sizeof(long int)<sizeof(long long int).<br />
For e.g. in 32 bits operating system sizeof(short int)=2 bytes, sizeof(int)=2bytes, sizeof(long int)=4bytes, sizeof(long long int)=4bytes.<br />
but in case of 64 bits operating system sizeof(long long int)=8bytes.<br />
So the bottom line is that size of integer is totally dependent on the machines and compilers.<br />
<br />
<br /></div>
jameshttp://www.blogger.com/profile/06329212436216944855noreply@blogger.com0