C language Tutorial with programming approach for beginners and professionals, helps you to understand the C language tutorial easily. Our C tutorial explains each topic with programs.
The C Language is developed for creating system applications that directly interact with the hardware devices such as drivers, kernels, etc.
C programming is considered as the base for other programming languages, that is why it is known as mother language.
It can be defined by the following ways:
QUALIFICATION: Masters from IISC Bangalore PROFESSIONAL EXPIERENCE: 9+ years of Experience( Yahoo Labs, Matherix Labs Co-founder and Amazon)
Sir I have attended today's interactive session of C programming , but didn't understand some concepts ,Are Interactive sessions are for those students who have completed the course ?
Login to replyRecommend Book for maximum solved questions related to Pointers, Strings
Login to replyUnderstanding pointers in C by Yashwant Kanethkar is a good book chapter 1-3 will build your understanding, it contains many examples and problems.
Login to reply
1.y cant we apply int a=1,2,3? instead we need to first declare(int a;) and then intialize a=1,2,3.but as per operator precedence Assignment has higest precendence it should be intialized with 1? what is the reason behind it.
But if we use int a=(1,2,3) . it will working fine.
2.
When we write int a,b; both a and b are identifiers.
Similarly here in int a=1,2,3;
compiler treat 2 and 3 as identifiers and identifiers should start from letter or underscore only. So, it will produce error.
At 11.29AM@, Compiler is also a program. Then compiler itself is written in which language?? And how computer understands the program of compiler??
Login to reply
The story for C has multiple steps. The first C compiler was written in B (a predecessor to C) which in turn was written in BCPL. BCPL is a pretty simple language (for example it doesn't have types at all), but still a step up from raw assembler. So we see how gradually more complex languages is build in simpler languages all the way back to assembler. And itself C is a pretty small and simple language by todays standards.
Today, the first compiler for a new language is often written in C, but when the language reaches a certain maturity it is often rewritten "in itself". The first Java compiler was written in C, but later rewritten in Java. The first C# compiler were written in C++, but recently it has been rewritten in C#. The Python compiler/interpreter is written in C, but the PyPy project is an attempt to rewrite it in Python.
There are phases involved in compiler that we will see in compiler design subject. It converts into intermediate code then, target code is generated then, assembly code is generated, we discuss in detail all about this in compiler design course.
int main()
{
int a,b,c,d,e,f;
a=2%5;
b=-2%5;
c=2%-5;
d=-2%-5;
e=5%2;
f=-5%-2;
printf("%d %d %d %d %d %d",a,b,c,d,e,f);
return 0;
}
output = 2 -2 2 -2 1 -1
Sir, why it is so? Remainder cannot be negative. Please explain it.
Remainder always gives numenator sign. -2/-5=-5*0+(-2)
-5/-2=-2*2+(-1)
5/-2=-2*(-2)+1
Recommend Book for maximum solved questions related to LOOPS
Login to replyYou can refer C in depth by Deepali Srivastava, Let US C by Yashwant Kanetkar or C Programming language by Dennis M. Ritchie.
Login to replySir, When I execute the following code, #include int main() { int i = 300; char *ptr = &i; *++ptr = 2; printf("%d",i); return 0; } It prints 556. Shouldn't it be 258? The second byte of "i" should be set to 2 right?
Login to reply
In the lower byte value will be 300-256=44.
In the upper byte, you are doing *++ptr=2;
So, it will be 00000010 00101100=512+44=556.
Hi Sir where can I practice a bunch of questions for c programming so that questions asked in gate are either very easy or are very similar to the ones that I have solved?
Login to reply
HI,
(++*c)++ what about this expression, what does it return because compiler is giving error: expression is not assignable.
Yes, you are trying to increment an r-value.
Any increment operation like a++ means a statement like this: a = a + 1.
Let's say int a = 10, *c = &a;
(++*c)++;
The result of ++*c is a r-value 11. Then when you do 11++ this gives a compilation error.
You are doing an operation like this:
11 = 11 + 1; instead of an operation like this: *c = *c + 1;
https://en.wikipedia.org/wiki/Value_(computer_science)
Why cant I see the video in fullscreen ?
Login to reply
This is the first video of course itself.
Here is the link:
https://gate.appliedcourse.com/lecture/2/c-programming/538/c-what-why-and-how/45/introduction-and-basics-of-c-programming
#include int main() { int x = 1, y = 1; printxy(x,y); return 0; } void printxy(int x, int y) { int *ptr; x = 0; // ptr point to variable of value 0 ptr = &x; // y has value pointed by ptr -> x= 0; y = *ptr; // value pointed by ptr is set to 1 -> x= 1; *ptr = 1; //x be changed to 1 and y will remain 0 printf("%d,%d", x, y); } o/p :1, 0 why is it not 1,1 - both point to same memory location
Login to replyInitially x=0 and ptr points to x. So, y=*ptr, y=0 hence, value of y=0, it will not be automatically change in C by changing *ptr value.
Login to reply
Consider the following C code
int main()
{
int a = 300;
char *b = (char *)&a;
*++b = 2;
printf("%d ",a);
return 0;
}
Consider the size of int as two bytes and size of char as one byte. Predict the output of the
following code . Assume that the machine is little-endian
o/p:556
please explain
In the lower byte value will be 300-256=44.
In the upper byte, you are doing *++ptr=2;
So, it will be 00000010 00101100=512+44=556.
Consider the following C code
int main()
{
int a = 300;
char *b = (char *)&a;
*++b = 2;
printf("%d ",a);
return 0;
}
o/p : 556
please explain
In the lower byte value will be 300-256=44.
In the upper byte, you are doing *++ptr=2;
So, it will be 00000010 00101100=512+44=556.
Given the following pseudocode for function below, how many times is printed if we execute void printx(int n) { if(n==0){ printf(“x”); } for(int i=0;i
Login to reply
Here, T(n)=nT(n-1), n>0 and T(0)=1
So, T(1)=1*T(0)=1
T(2)=2*T(1)=2=2!
T(3)=3*T(2)=6=3!
..
So, T(n)=n*(n-1)!=n!
Sir the practice test is supported in phone or not???
Login to replyYes, it will be supported but from browser, please click on desktop site.
Login to replyHello Sir, I had a queestion: Why C/C++ is the fastest as compared to other language? What is there in C which makes it so faster? Is it because of its compiler?
Login to replyC/C++ are performance effective as they directly translate high-level code to machine dependent instructions unlike other languages. Java translates code to byte code then from byte code to machine dependent instructions. Such intermediate translation layer is not required by C/C++ so they are more performance effective.
Login to replyFrom where to attend the practice test 1?
Login to replyIn Curriculum, click on Pratice Test-1 Introduction to C-Programming, there you can find Pratice Test-1.
Login to replyIn mobile it doesn't show practice test it only shows solution to practice test-1
Login to replyPlease check curriculum Introduction to C Programming in that you can find Practice Test-1
Login to reply
int main()
Login to reply{
int i=8;
i=i++;
printf("%d",i);
return 0;
}
why its answer is 8? it should be 9
Because it is post increment operator. Initially i=8 and in second line i=i++ ; i.e. i= 8++; before semi colon it's value will be 8 only so 8 will be stored in i. and in third line printf("%d", i); value of i is printing so it will print 8. but if you write i ++; and
Login to replyprint (i) in second line then it will give value 9.
sir here "i" will get two values 8,9 how come only 8 is being printed because post increment says first copy the value and then increment so now i=8 is copied ,after copying i will be incremented to 9 now since we are printing i so i should be 9 but here 8 is printed so the incremented value of i i.e 9 where will it be stored??
Login to replyThe C programming language has undefined behaviour it can get tricky in few cases refer the below stack overflow link for more clarity and other such cases.
Login to replyhttps://stackoverflow.com/questions/949433/why-are-these-constructs-using-pre-and-post-increment-undefined-behavior
Hello Ayush,
Login to replyThe thing is that post increement assigns the value to the variable first and then it increases later. So, here it will first assing the value to "i" which is "8" and yet not changed/incremented. Later, as soon as the statement executes, it gets increased to 9 but since the value of i is already assigned and i++ is incremented after assignment but never stored in any variable so we can not see. Please correct meif I am getting it wrong.
@Shubham Dwivedi,
Login to replysince it is a post increment the assignment will happen first and therefore i will be assigned the value 8 but after the assignment increment will be done which will increase the value of i to 9 and hence 9 should be printed.
Why did u say that i is incremented but never stored in any variable i++ in itself mean i=i+1.?
For example, When you write: int x = *p++; it increments the pointer after assigning the value, it's not like that it doesn't store the value.
The answer should be undefined here
Here, output will be 8 not 9.
Login to replyhttps://onlinegdb.com/S1evEKyQv
But this is also Compiler Dependent? because in various online compiler its will have undefined behavior
Login to replyYes, it is compiler dependent, because it comes under the "undefined behavior" of the C language.
Login to replyThe main problem is this statement:
i = i++;
Whenever we are trying to modify the same variable more than once in a single statement, we walk into undefined territory. Anything can happen.
In this particular case this is happening:
temp = i;
i++;
i = temp;
So, in this way i is storing 8 and not 9.