Macros are preprocessor directives that are defined using #define directive. Macros consist of two parts Macro_Name, & Macro_Substitution_Text.
Before the source code gets complied, the preprocessor will check for the presence of macros. & wherever it found that macro simply replaces that macros with substitution text.
Macros are not Type Safe.
void main()
{
int i,j;
for(i=0;i<=2;i++)
{
for(j=2;j>i;j--)
printf(" ");
for(j=1;j<(i+1);j++)
{
printf("%d",mod(j-i));
}
printf("/n");
}
getch();
}
------------------------------void main()
{
int i,j;
for(i=0;i<=2;i++)
{
// for(j=2;j>i;j--)
// printf(" ");
for(j=1;j<(i+1);j++)
{
printf("%d",mod(i-j));
}
printf("/n");
}
getch();
}
--------------------------------
void main()
{
int i,j;
for(i=0;i<=2;i++)
{
//for(j=2;j>i;j--)
// printf(" ");
for(j=1;j<(i+1);j++)
{
printf("%d",mod(j-i));
}
printf("/n");
}
getch();
}
-------------------------
void main()
{
int i,j,k=1;
for(i=0;i<=3;i++)
{
for(j=3;j>i;j--)
printf(" ");
for(j=1;j<(i+1);j++)
{
k=k+1;
printf("%d",k);
}
printf("/n");
}
getch();
}
3. How to reverse a linked list without using array & -1?
IS it possible by sorted list???.
It's a human mistake associated with the program
5. What is meant for variable not found?
when u have not declared variable in the main function or
any other function but used in the program.
example:
main()
{
int i,j;----------------> (iSum not declared)
printf("enter the value of i and j");
scanf("%d%d",&i,&j);
iSum = i + j;
printf("The Sum =",iSum);
getch();
}
In this case iSum will Show a compiler error "Variable not
found".
synatx error is a compile type error. it will occur when
the programmer doesnot follow the standard rules or
syntax of programming.
here in first statement
printf("%d",++i + --z + i++ + --i * ++y);
argument is : ++i + --z + i++ + --i * ++y.
first it will maintain stack operation like
++y (now fifth, it will execute and, y=4)(top 4)
--i (now fourth, it will execute and, i=6)
(because, last value of i were 7, once i++ were
executed, now --i will less one value in i)(top 3)
i++ (now third, it will execute and, i=6, it will
as it is, its value will for next stack value.)
(top 2)
--z (now second, it will execute and, z=1)(top 1)
++i (first it will execute and, i=6)(top 0)
now (++i + --z + i++ + --i * ++y)
(6+1+6+6*4)=(37)
it is output, say 37,for this printf("%d",++i + --z + i++
+ --i * ++y);
.................................................
Now Let me go with second statement, that is :
ans=++i + --z + i++ + --i * ++y;
here,
first of all ++y will contain the value of variable y=4
++y=4
after this, --i will less the value of variable i, say now
i = 4,
(--i=4),
after this, i++ will execute and, it will not increase the
value of variable i, right now, so value of i, say now i =
4, as it is.
after this, --z will less the value of variable z, say now
z = 1,
(--z=1)
now, ++i will increase the value of variable i.
Say i = 5.
.......................................................
now value of valiable i in memory is 5.
ans=5+1+5+5*4
ans=5+1+5+20
ans=31..........,
8. void main()
{
int i=7;
printf("N= %*d",i,i);
}
Its output would be 7,
"%*d"
here * symbol doesn't affect of operation of %d.
so 7 is set to value in variable i.
An error that occurs during the execution of a program. In
contrast, compile-time errors occur while a program is
being compiled. Runtime errors indicate bugs in the program
or problems that the designers had anticipated but could do
nothing about. For example, running out of memory will
often cause a runtime error.
A runtime error is a computer error that appears in
the form of a message box consisting of a particular code
along with its corresponding definitions. Usually, a user
will notice that the computer becomes noticeably slow
before a runtime error appears.
After the runtime error message has been displayed and
closed, the software that shows this error would normally
close or freeze. In some cases, the operating system will
reboot.
10. char* f()
return "hello:";
void main()
{char *str=f();
}
str will be a pointer to "hello:"
so on printing str will output hello:
If you are using Turbo C complier need to add #include<iostream.h> header file.
and If you are using Visual Studio then you need to add
#include<iostream>
using std namespace;
the above two statements.
12. Can you explain exceptions?
An exception is an event, which occurs during the execution
of a program, that disrupts the normal flow of the program's
instructions.
The main reason is lengthy C programs lose "Global View" and
become very difficult to visualize as a single concept.
C++ is an advance than C lang which has more features...
But comparing efficiency C is more efficient than C++
But C++ has more flexibility than C.
Also C++ is both combination of OOP and OBP concepts.
C++ has more features as
1.Object oriented
2.Information hiding
3.Standard Template Library
4.Inheritance
5.Constructors & Destructors
6.Exception Handling
7.Overloading