Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

C program to swap two numbers using pointer

C program to swap two numbers using pointer

In this tutorial we will going to learn how to swap two numbers using pointer. If you want to learn more about pointer then you can go through my previous post Pointers in C Programming with Examples.

My System Configuration :

Fujitsu A555 with 12GB RAM, OS – Kubuntu 18.04, IDE used Geany (you can use your own favorite like Notepad++, Codeblock, Kate, Gedit, Sublime text …,  Compiler : GCC .

Complete Code for C program to swap two numbers using pointer


/*
* Filename : swappointer.c
* C program to swap two no
* using pointer
* By Sanjay Prasad
*/
#include <stdio.h>
void swap(int *n1, int *n2){
int temp;
temp=*n1;
*n1=*n2;
*n2=temp;
}
int main(){
int a,b;
printf("Enter 1st no. a : ");
scanf("%d",&a);
printf("\nEnter 2nd no. b: ");
scanf("%d",&b);
printf("\na contain %d",a);
printf("\nb contain %d",b);
swap(&a,&b);
printf("\nAfter Swap \na contain %d",a);
printf("\nAfter Swap \nb contain %d",b);
printf("\n");
return 0;
}

How to Compile and Run :

first create a file named swappointer.c somewhere. Open terminal and using cd to go there and use command given below :

gcc swappointer.c  (will compile code)

./a.out   (will execute code)

 

Pointers in C Programming with Examples

Pointers in C Programming with Examples

What is a pointer? Explain pointer arithmetic with example. Also explain use of malloc function in C programming with an example.

Pointer :
A pointer is a variable that points to or references a memory location in which data is stored. Each
memory cell in the computer has an address that can be used to access that location so a pointer
variable points to a memory location we can access and change the contents of this memory location
via the pointer.

Pointer declaration:
A pointer is a variable that contains the memory location of another variable. The syntax is as shown
below. You start by specifying the type of data stored in the location identified by the pointer. The
asterisk tells the compiler that you are creating a pointer variable. Finally you give the name of the
variable.
type * variable name
Example:
int *ptr;
float *string;

Pointer Arithmetic
Like other variables pointer variables can be used in expressions. For example if p1 and p2 are
properly declared and initialized pointers, then the following statements are valid.
y=*p1**p2;
sum=sum+*p1;
z= 5* – *p2/p1;
*p2= *p2 + 10;
C allows us to add integers to or subtract integers from pointers as well as to subtract one pointer
from the other. We can also use short hand operators with the pointers p1+=; sum+=*p2; etc., we can
also compare pointers by using relational operators the expressions such as p1 >p2 , p1==p2 and p1!
=p2 are allowed.

/*Program to illustrate the pointer expression and
pointer arithmetic*/
#include< stdio.h >
main(){
int ptr1,ptr2;
int a,b,x,y,z;
a=30;b=6;
ptr1=&a;
ptr2=&b;
x=*ptr1+ *ptr2 –6;
y=6*- *ptr1/ *ptr2 +30;
printf(“\nAddress of a +%u”,ptr1);
printf(“\nAddress of b %u”,ptr2);
printf(“\na=%d, b=%d”,a,b);
printf(“\nx=%d,y=%d”,x,y);
ptr1=ptr1 + 70;
ptr2= ptr2;
printf(“\na=%d, b=%d”,a,b);
}

Malloc Function

Description:
The function malloc() returns a pointer to a chunk of memory of size size, or NULL if there is an
error. The memory pointed to will be on the heap, not the stack, so make sure to free it when you are

done with it. It is basically used in Dynamic Memory Allocation.
Example:
typedef struct data_type {
int age;
char name[20];
} data;
data *person;
bob = (data*) malloc( sizeof(data) );
if( person != NULL ) {
person->age = 22;
strcpy( person->name, “Robert” );
printf( “%s is %d years old\n”, person->name, person->age );
}
free( person );

How to Add INR as New Currency in Opencart 3.x and make it default (Video)

How to Add INR as New Currency in Opencart 3.x and make it default (Video)

Adding Indian Currency in Opencart is really simple. Just follow the steps or watch Video How to Add a INR as New Currency in OpenCart 3.x and make it default Currency below it will hardly take 3 minutes.

For Adding Indian Currency INR Go to

System > Localization > currencies
Create new Currency with the following details
Currency Title – Indian Rupee
Code – INR
Symbol Left – ₹
Decimal Places – 2
Status – enabled

Now Changing INR as default default currency … Go to
System > Settings > Local (Tab)
change Country, Region / State, Currency

Watch Video How to Add INR as New Currency in Opencart 3.x and make it default Currency

I think its very simple, this was successfully tested on Open Cart 2.X,3.X , if you have any problem then let me know through comments or register on my website to discuss.

CBSE Class 10 Exam. Date Sheet for year 2020 Check CBSE Class 10 Time Table

CBSE Class 10 Exam. Date Sheet for year 2020 Check CBSE Class 10 Time Table

Central Board of Secondary Education (CBSE) has released Class 10 date sheet for year 2020 . CBSE Class 10 examination will start from 15th February 2020 . Students and Parents are advised to follow CBSE Official Website http://cbse.nic.in/ .

We have also included direct download link of Class 10 and 12 PDF, Download Links are given below :

DOWNLOAD CLASS X EXAM. SHEET PDF 2020

CBSE class 10 Examination List in short

Subject Name Date Time
Information Technology 20th FEB. 2020 10.30 AM -1.30 PM
Regional Lang. Like Bengali, Tamil , Punjabi …. 24th FEB. 2020 10.30 AM -1.30 PM
English 26th FEB. 2020 10.30 AM -1.30 PM
Hindi 29th FEB. 2020 10.30 AM -1.30 PM
Science 04th MARCH 2020 10.30 AM -1.30 PM
Sanskrit 7th MARCH 2020 10.30 AM -1.30 PM
Math. 12th MARCH 2020 10.30 AM -1.30 PM
Social Science 18th MARCH 2020 10.30 AM -1.30 PM

Display All PHP Errors

Display All PHP Errors

Sometime due to our lampp / xampp setup, we are not able to see php error it may be Waring or Fetal Error but fixing bugs we need to know all warnings and error details. In this post I am going to share a script so using this script we will be able to see those warning and errors.

PHP CODE TO DISPLAY ALL ERRORS

Add these lines to your  your php file  to see Warnings and Error

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL);

Please comment if you have and query or suggestion

Linux Error: unknown filesystem. grub rescue>

Linux Error: unknown filesystem. grub rescue>

Recently when trying Kubuntu 19.04 as dual boot with Ubuntu I got a error “Error: unknown filesystem. grub rescue>”, I can’t boot my system and also not able to boot any live USB as my system gone to GRUB2 Rescue Mode.

then I tried the code below
grub rescue>ls (hd0) (hd0,1) (hd0,2) (hd0,3) (hd0,4)
then I tried
grub rescue> set root=(hd0,2)
grub rescue> set prefix=(hd0,2)/boot/grub
grub rescue> insmod normal
grub rescue> normal

Note : (hd0,2) is working for me.
Now once you boot into Ubuntu, run the following two commands as well:

sudo update-grub
sudo grub-install /dev/sda

Now my system works boot normally .

PHP Getting Best two of Three Numbers for CBSE Result Tabulation

PHP Getting Best two of Three Numbers for CBSE Result Tabulation

In this post I will show how to get best two out of Three Numbers using PHP, Actually I have developed CBSE based School ERP for Our company and for generating Result tabulation you need to find out best two numbers from T1,T2 and T3. Lets dive into code without wasting time ..

Script / Code to find out best two out of Three Numbers

<?php
/*
* Getting Best two of Three Numbers
* By Sanjay Prasad
*/
$fd1=10;
$fd2=11.5;
$fd3=8.5;
$num1=number_format($fd1,1);
$num2=number_format($fd2,1);
$num3=number_format($fd3,1);
$num=array($num1,$num2,$num3);
rsort($num);
//var_dump($num);
$fd4 = $num[0] + $num[1];
echo $fd4;
//output will be 21.5
?>

RRB NTPC 2019 Most Important Question Current Affairs

RRB NTPC 2019 Most Important Question Current Affairs

RRB is going to conduct RRB NTPC Examination soon, so in this post I am going to post some of most important Current Affairs question with their answer.

What is RRB NTPC Examination!

The RRB NTPC is a competitive exam for the non-technical posts conducted by Railway Recruitment Board. The full form of NTPC is Non-Technical Popular Categories.

RRB NTPC 2019 Most Important Question with their answer

1. Who became the first Indian Wrestler to qualify for the 2020 Tokyo Olympics?
Answer : Vinesh Phogat.
2. In which country is the tallest tower in South Asia unveiled ?
Answer : Sri Lanka.
3. Each year World Red Cross and Red Crescent Day is celebrated on !
Answer : Friday, 8 May.
4. Pandit Jasraj has established his reputation in which of the following fields?
Answer : Music .
5. Who is the director of the Indian documentary film ‘Moti Bagh’ nominated for the 2019 Oscars?
Answer : Nirmal Chandra
6. Who won the 2019 IBSF World Billiards Championship title in Myanmar?
Answer : Pankaj Adwani.
7. Which scientist discovered the radioactive element radium?
Answer : Marie Curie.
8. Tripitakas are sacred books of a) Hindus b) Jews c) Jains d) Buddhists.
Answer : d) Buddhists
9) Which Indian cricketer has been appointed the first Chancellor of Rai Sports University in Sonipat?
Answer : Kapil Dev
10) When was the Howdy Modi program organized?
Answer : 22th September, 2019.
11. In which country will the FIFA Under 17 Women’s World Cup 2020 be held?
Answer : India.
12. Which state government has decided to ban private practice of government doctors?
Answer : Andhra Pradesh
13. SYED MUSHTAQ ALI TROPHY is associated with
a) Hockey b) Cricket c) Basketball d) Football.
Answer : Cricket
14. Who won 2019 Cricket World cup (ODI) .
Answer : England
15. In Human beings the process of digestion of food begins in a) Stomach b) Food Pipe c) Mouth
d) Small Intestine .
Answer : C) Mouth.
16.Which of the following organism have parasitic mode of nutrition?
a) Penicillium
b) Plasmodium
c) Paramecium
d) Parrot
Answer : b) Plasmodium
17.Name the first enzyme that mix with food in the digestive tract?
a) Pepsin
b) Trypsin
c) Amylase
d) None of the above
Answer : c) Amylase
18.The solution of one of the following compounds will conduct electricity. This compound is:
a) CCl4
b) HCl
c) CaCl2
d) CH3Cl
Answer: c) CaCl2 (calcium chloride)
Explanation: CaCl2 form ionic bond and so will conduct electricity.
19. Which of the following in biology is the energy currency of cells?
a) PDP
b) DTP
c) ATP
d) ADP
Answer: c) ATP
20. Which animal has three-chambered heart?
a) Pigeon
b) Lizard
c) Fish
d) Lion
Answer: b) Lizard (Generally Amphibians and reptiles has 3 chambered heart)

Fedora 31 released Officially, Check Out its New Features

Fedora 31 released Officially, Check Out its New Features

Fedora 31 released Officially, Check Out its New Features
Fedora 31 is released officially, so one can download it from its official website getfedora.org and enjoy its new features report bugs or set fedora 31 as own primary workstation or development environment if you are developer.

Whats new in Fedora 31

Toolboox
As per fedoramagazine.org “If you haven’t used the Fedora Toolbox, this is a great time to try it out. This is a simple tool for launching and managing personal workspace containers, so you can do development or experiment in an isolated experience. It’s as simple as running “toolbox enter” from the command line.
This containerized workflow is vital for users of the ostree-based Fedora variants like CoreOS, IoT, and Silverblue, but is also extremely useful on any workstation or even server system. Look for many more enhancements to this tool and the user experience around it in the next few months — your feedback is very welcome.”

Distro Name Fedora
Based On RPM based
Distro Version Fedora 31
Desktop Environment GNOME 3.34
Website getfedora.org
Download Download Fedora 31 Workstation 64bit
Karnel 5.0
Grub NA
Systemd 243
Samba 4.11.2
Shell Bash 5.0
GCC 9.2.1
QT 5.12.5
Python 3.8
NodeJS 12
VIM 8.1
File Manager Nautilus (3.34.1)
Java
Browser Firefox 70
Email Client Thunderbird 68.2.0
Video Player NA
Office Libra Office 6.3.3

Honor Lite 10 best phone under 7500Rs. with Antutu score135000

Honor Lite 10 best phone under 7500Rs. with Antutu score135000

Honor 10 Lite 3GB/32GB priced Rs. 7999 (After 10% Credit/Debit card discount Rs. 7200), is looks like a Premium Smart phone that can be seen on high end phone and tons of feature with average Antutu score 135000.

Should I buy Honor Lite 10 3GB/32GB

Pros:
Excellent performance.
PUBG on HD, High FPS without lag. From 100-0% battery.

Excellent battery
5-5.5 hours of PUBG on HD, High FPS, 50% brightness.
It lasts longer than many 4000 mAh phones like Redmi Note 7.

Excellent built quality.
I’ve checked all phones close to its price range. Honor 10 Lite and Realme 3 strongest phone around.

Excellent sound quality in speaker + earphones.
It’s loud, clear and stereo! Flipkart, amazon Gsmarena, 91mobiles also rated it excellent in their review.
The sound quality is better than all phones in its price (in my country).

Cons:
Rear Camera can be improved little bit.
Missing Infrared blaster, USB C-Type, Blutooth 5, Only 10W Fast Charging .

Honor Lite 10 3GB/32GB, Antutu Score and pros and Cons

Specification Remarks
ANTUTU SCORE Average Score 135,000 Very Good
Gaming PubG Can be played in Medium graphic Can be played most of the games smoothly using GPU Turbo 3
SOC Hisilicon Kirin 710 (12 nm)
GPU – Mali-G51 MP4
Good and Power Efficeient
OS Android 9.0 (Pie); EMUI 9.1 Well optimized, lag free and butter smooth
Android 10 Honor will provide android 10 Listed on Android 10 on Honor Website
RAM and ROM 3GB RAM 32GB ROM Excellent
Battery 3400mAH, Battery charging 10W Good enough for 1day usages
Dimension 154.8 x 73.6 x 8 mm (6.09 x 2.90 x 0.31 in)
162 g
Very Light weight and small
Display 6.21 inches inch FHD+
1080 x 2340 pixels, 19.5:9 ratio (~415 ppi density)
Excellent
Camera 13 MP, f/1.8, 26mm (wide), PDAF
2 MP, f/2.4, depth sensor,
Secondary 24MP
with AI get get better quality images
Video Rear Camera 1080p@30/60fps

Secondary 1080p@30fps

with AI get get better quality videos
OTG Yes
Infrared Blaster No
NFC No
Dual Active VoLTE Yes can run two jio sim ..
Bluetooth  version 4.2 Expected 5
FM Radio Yes
Sensor Fingerprint, G-sensor, Proximity, Light, Compass
GPS A-GPS, GLONASS, BDS Better GPS Lock
Sound Good Enough not Loud

Final Thought
At Rs. 7999 (After 10% Credit/Debit card discount Rs. 7200), no phone compete honor 10 lite, with Premium Look that can be
seen on high end phone and tons of feature it will going to be the best Buy.

Do you have any Query / Suggestion