Archive for cpp language programs

You are browsing the archives of cpp language programs.

C++ Aptitude and OOPS

1)

class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
[...]

aptitude c programs with answers

main(int argc, char **argv)
{
printf("enter the character");
getchar();
sum(argv[1],argv[2]);
}
sum(num1,num2)
int num1,num2;
{
return num1+num2;
}

Answer:
Compiler error.
Explanation:
argv[1] & argv[2] are strings. They are passed to the function sum without converting it to integer values.
82)

# include <stdio.h>
int one_d[]={1,2,3};
main()
{
int *ptr;
ptr=one_d;
ptr+=3;
printf("%d",*ptr);
}

Answer:
garbage value
Explanation:
ptr pointer is pointing to out of the array range of one_d.
83)

# include<stdio.h>
aaa() {
[...]