C Programming

Category: Gate CSE

C Programming

Category: Gate CSE
₹3,500.00 ₹9,000.00
Cinque Terre
Instructor
Chekuri Srikanth Varma


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:

  1. Mother language
  2. System programming language
  3. Procedure-oriented programming language
  4. Structured programming language
  5. Mid-level programming language
Course Features
Lectures
75 Lecture
Duration
19+ Hours
Skill level
Easy
Language
English
Assessments
Yes

Cinque Terre

QUALIFICATION: Masters from IISC Bangalore PROFESSIONAL EXPIERENCE: 9+ years of Experience( Yahoo Labs, Matherix Labs Co-founder and Amazon)

C Programming

Category: Gate CSE
₹3,500.00 ₹9,000.00
Cinque Terre
Instructor
Chekuri Srikanth Varma

40 Comment(s)

Avatar Avyush Pandey  19 Votes

int main()
{
int i=8;
i=i++;
printf("%d",i);
return 0;
}
why its answer is 8? it should be 9

Login to reply
Avatar Instructor 

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
print (i) in second line then it will give value 9.

Login to reply
Avatar Cherukuri Venkta Sai Narendra 

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 reply
Avatar Instructor GATE 

The 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.
https://stackoverflow.com/questions/949433/why-are-these-constructs-using-pre-and-post-increment-undefined-behavior

Login to reply
Avatar Shubham Dwivedi 

Hello Ayush,
The 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.

Login to reply
Avatar Vinay Yadav 

@Shubham Dwivedi,
since 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

Login to reply
Avatar Mentors GATE 

Here, output will be 8 not 9.
https://onlinegdb.com/S1evEKyQv

Login to reply

Avatar Ashish Mishra  5 Votes

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 reply

Avatar Amit Sharma  5 Votes

Recommend Book for maximum solved questions related to Pointers, Strings

Login to reply
Avatar Mentors GATE 

Understanding 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

Avatar Yerabolu Shanmukha raja Srinivas  1 Votes

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.

Login to reply
Avatar Mentors GATE 

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. 
 

Login to reply

Avatar Isha  1 Votes

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.

Login to reply
Avatar Mentors GATE 

Remainder always gives numenator sign. -2/-5=-5*0+(-2)
-5/-2=-2*2+(-1)
5/-2=-2*(-2)+1

Login to reply

Avatar Udit Gavasane  0 Votes

Why cant I see the video in fullscreen ?

Login to reply

Avatar Sudipto Das  0 Votes

#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 reply
Avatar Mentors GATE 

Initially 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

Avatar Sudipto Das  0 Votes

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

Login to reply
Avatar Mentors GATE 

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.

Login to reply

Avatar Sudipto Das  0 Votes

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

Login to reply
Avatar Mentors GATE 

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.

Login to reply

Avatar Isha  0 Votes

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
Avatar Mentors GATE 

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. 

Login to reply

Avatar Aditya Kumar Singh  0 Votes

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
Avatar Mentors GATE 

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!

Login to reply

Avatar Mohd arfeen  0 Votes

Sir the practice test is supported in phone or not???

Login to reply
Avatar Mentors GATE 

Yes, it will be supported but from browser, please click on desktop site.

Login to reply

Avatar jatin kumar sachan  0 Votes

Recommend Book for maximum solved questions related to LOOPS

Login to reply
Avatar Mentors GATE 

You can refer C in depth by Deepali Srivastava, Let US C by Yashwant Kanetkar or C Programming language by  Dennis M. Ritchie.

Login to reply

Avatar Shubham Dwivedi  0 Votes

Hello 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 reply
Avatar Mentors GATE 

C/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 reply

Avatar Mukesh N Chugani  0 Votes

Sir, 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
Avatar Mentors GATE 

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. 

Login to reply

Avatar Dharmesh Sharma  0 Votes

From where to attend the practice test 1?

Login to reply
Avatar Mentors GATE 

In Curriculum, click on Pratice Test-1 Introduction to C-Programming, there you can find Pratice Test-1. 

Login to reply
Avatar Dharmesh Sharma 

In mobile it doesn't show practice test it only shows solution to practice test-1

Login to reply
Avatar Mentors GATE 

Please check curriculum Introduction to C Programming in that you can find Practice Test-1

Login to reply

© 2020 - All rights are reserved- AAIC Technologies pvt ltd